Skip to content

Commit e840343

Browse files
committed
Changing variable for clarity and removing unnecessary line break thanks to @OskarStark
1 parent c5fa409 commit e840343

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

reference/forms/types/choice.rst

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,29 @@ This field has a *lot* of options and most control how the field is displayed. I
8787
this example, the underlying data is some ``Category`` object that has a ``getName()``
8888
method::
8989

90-
$builder
91-
->add('category', 'choice', [
92-
'choices' => [
93-
new Category('Cat1'),
94-
new Category('Cat2'),
95-
new Category('Cat3'),
96-
new Category('Cat4'),
97-
],
98-
'choices_as_values' => true,
99-
'choice_label' => function($val, $key, $index) {
100-
/** @var Category $val */
101-
return strtoupper($val->getName());
102-
},
103-
'choice_attr' => function($val, $key, $index) {
104-
return ['class' => 'category_'.strtolower($val->getName())];
105-
},
106-
'group_by' => function($val, $key, $index) {
107-
// randomly assign things into 2 groups
108-
return rand(0, 1) == 1 ? 'Group A' : 'Group B'
109-
},
110-
'preferred_choices' => function($val, $key, $index) {
111-
return $val->getName() == 'Cat2' || $val->getName() == 'Cat3';
112-
},
113-
]);
90+
$builder->add('category', 'choice', [
91+
'choices' => [
92+
new Category('Cat1'),
93+
new Category('Cat2'),
94+
new Category('Cat3'),
95+
new Category('Cat4'),
96+
],
97+
'choices_as_values' => true,
98+
'choice_label' => function($category, $key, $index) {
99+
/** @var Category $category */
100+
return strtoupper($category->getName());
101+
},
102+
'choice_attr' => function($category, $key, $index) {
103+
return ['class' => 'category_'.strtolower($category->getName())];
104+
},
105+
'group_by' => function($category, $key, $index) {
106+
// randomly assign things into 2 groups
107+
return rand(0, 1) == 1 ? 'Group A' : 'Group B'
108+
},
109+
'preferred_choices' => function($category, $key, $index) {
110+
return $category->getName() == 'Cat2' || $category->getName() == 'Cat3';
111+
},
112+
]);
114113

115114
You can also customize the `choice_name`_ and `choice_value`_ of each choice if
116115
you need further HTML customization.

0 commit comments

Comments
 (0)