@@ -47,8 +47,8 @@ Suppose you have a Task form with a tags ``text`` type::
47
47
// ...
48
48
}
49
49
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.
52
52
53
53
This is a *perfect * time to attach a custom data transformer to the ``tags ``
54
54
field. The easiest way to do this is with the :class: `Symfony\\ Component\\ Form\\ CallbackTransformer `
@@ -69,13 +69,13 @@ class::
69
69
70
70
$builder->get('tags')
71
71
->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 );
75
75
},
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 );
79
79
}
80
80
))
81
81
;
@@ -84,10 +84,10 @@ class::
84
84
// ...
85
85
}
86
86
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.
91
91
92
92
.. tip ::
93
93
@@ -99,7 +99,8 @@ You can also add the transformer, right when adding the field by changing the fo
99
99
slightly::
100
100
101
101
$builder->add(
102
- $builder->create('tags', 'text')
102
+ $builder
103
+ ->create('tags', 'text')
103
104
->addModelTransformer(...)
104
105
);
105
106
0 commit comments