Skip to content

Commit 68d1f8b

Browse files
committed
Renamed the values in callback functions of ChoiceType to make them more consistent with eachother and the code.
1 parent b0fd087 commit 68d1f8b

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

reference/forms/types/choice.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,17 @@ method::
9494
new Category('Cat3'),
9595
new Category('Cat4'),
9696
],
97-
'choice_label' => function($category, $key, $value) {
98-
/** @var Category $category */
97+
'choice_label' => function(Category $category, $key, $value) {
9998
return strtoupper($category->getName());
10099
},
101-
'choice_attr' => function($category, $key, $value) {
100+
'choice_attr' => function(Category $category, $key, $value) {
102101
return ['class' => 'category_'.strtolower($category->getName())];
103102
},
104-
'group_by' => function($category, $key, $value) {
103+
'group_by' => function(Category $category, $key, $value) {
105104
// randomly assign things into 2 groups
106105
return rand(0, 1) == 1 ? 'Group A' : 'Group B';
107106
},
108-
'preferred_choices' => function($category, $key, $value) {
107+
'preferred_choices' => function(Category $category, $key, $value) {
109108
return $category->getName() == 'Cat2' || $category->getName() == 'Cat3';
110109
},
111110
]);

reference/forms/types/options/choice_attr.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If an array, the keys of the ``choices`` array must be used as keys::
1919
'No' => false,
2020
'Maybe' => null,
2121
],
22-
'choice_attr' => function($choiceValue, $key, $value) {
22+
'choice_attr' => function($choice, $key, $value) {
2323
// adds a class like attending_yes, attending_no, etc
2424
return ['class' => 'attending_'.strtolower($key)];
2525
},

reference/forms/types/options/choice_label.rst.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ more control::
1616
'no' => false,
1717
'maybe' => null,
1818
],
19-
'choice_label' => function ($value, $key, $choiceValue) {
20-
if (true === $value) {
19+
'choice_label' => function ($choice, $key, $value) {
20+
if (true === $choice) {
2121
return 'Definitely!';
2222
}
2323

@@ -28,8 +28,8 @@ more control::
2828
},
2929
]);
3030

31-
This method is called for *each* choice, passing you the ``$value`` and
32-
``$key`` from the choices array (additional ``$choiceValue`` is related to `choice_value`_).
31+
This method is called for *each* choice, passing you the ``$choice`` and
32+
``$key`` from the choices array (additional ``$value`` is related to `choice_value`_).
3333
This will give you:
3434

3535
.. image:: /_images/reference/form/choice-example2.png

reference/forms/types/options/group_by.rst.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Take the following example::
2222
'1 week' => new \DateTime('+1 week'),
2323
'1 month' => new \DateTime('+1 month'),
2424
],
25-
'group_by' => function($choiceValue, $key, $value) {
26-
if ($choiceValue <= new \DateTime('+3 days')) {
25+
'group_by' => function($choice, $key, $value) {
26+
if ($choice <= new \DateTime('+3 days')) {
2727
return 'Soon';
2828
} else {
2929
return 'Later';

reference/forms/types/options/preferred_choices.rst.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ be especially useful if your values are objects::
3333
'1 week' => new \DateTime('+1 week'),
3434
'1 month' => new \DateTime('+1 month'),
3535
],
36-
'preferred_choices' => function ($value, $key) {
36+
'preferred_choices' => function ($choice, $key, $value) {
3737
// prefer options within 3 days
38-
return $value <= new \DateTime('+3 days');
38+
return $choice <= new \DateTime('+3 days');
3939
},
4040
]);
4141

0 commit comments

Comments
 (0)