Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2333190

Browse files
committed
[#6581] Small improvements
1 parentb1ec264 commit2333190

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

‎cookbook/form/data_transformers.rst

Lines changed: 14 additions & 13 deletions
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 they are displayed
51+
to the user as a simplecomma seperatedstring, 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 array to string so the input reads easier
74+
return implode(', ', $tagsAsArray);
7575
},
76-
function ($submittedTags) {
77-
// transform the string back toArray
78-
return explode(', ', $submittedTags);
76+
function ($tagsAsString) {
77+
// transform the string back toan 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 transformsthe original value into a format that'll be used to render the
89+
field. The seconddoes the reverse: it transforms the submitted value back into
90+
the format you'll usein 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)

[8]ページ先頭

©2009-2025 Movatter.jp