Skip to content

Commit c8f4583

Browse files
committed
[symfony#6581] Some minor improvements
1 parent d042351 commit c8f4583

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

cookbook/form/data_transformers.rst

+14-13
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Suppose you have a Task form with a tags ``text`` type::
4747
// ...
4848
}
4949

50-
Internally the ``tags`` are stored as an array, but they are displayed
51-
to the user as a simple string, to make them easier to edit.
50+
Internally the ``tags`` are stored as an array, but displayed to the user as a
51+
simple comma seperated string to make them easier to edit.
5252

5353
This is a *perfect* time to attach a custom data transformer to the ``tags``
5454
field. The easiest way to do this is with the :class:`Symfony\\Component\\Form\\CallbackTransformer`
@@ -69,13 +69,13 @@ class::
6969

7070
$builder->get('tags')
7171
->addModelTransformer(new CallbackTransformer(
72-
// transform array to string so the input reads easier
73-
function ($originalTags) {
74-
return implode(', ', $originalTags);
72+
function ($tagsAsArray) {
73+
// transform the array to a string
74+
return implode(', ', $tagsAsArray);
7575
},
76-
function ($submittedTags) {
77-
// transform the string back to Array
78-
return explode(', ', $submittedTags);
76+
function ($tagsAsString) {
77+
// transform the string back to an array
78+
return explode(', ', $tagsAsString);
7979
}
8080
))
8181
;
@@ -84,10 +84,10 @@ class::
8484
// ...
8585
}
8686

87-
The ``CallbackTransformer`` takes two callback functions as arguments. The first transforms
88-
the original value into a format that'll be used to render the field. The second
89-
does the reverse: it transforms the submitted value back into the format you'll use
90-
in your code.
87+
The ``CallbackTransformer`` takes two callback functions as arguments. The
88+
first transforms the original value into a format that'll be used to render the
89+
field. The second does the reverse: it transforms the submitted value back into
90+
the format you'll use in your code.
9191

9292
.. tip::
9393

@@ -99,7 +99,8 @@ You can also add the transformer, right when adding the field by changing the fo
9999
slightly::
100100

101101
$builder->add(
102-
$builder->create('tags', 'text')
102+
$builder
103+
->create('tags', 'text')
103104
->addModelTransformer(...)
104105
);
105106

0 commit comments

Comments
 (0)