Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ method::
new Category('Cat4'),
],
'choices_as_values' => true,
'choice_label' => function($category, $key, $index) {
'choice_label' => function($category, $key, $value) {
/** @var Category $category */
return strtoupper($category->getName());
},
'choice_attr' => function($category, $key, $index) {
'choice_attr' => function($category, $key, $value) {
return ['class' => 'category_'.strtolower($category->getName())];
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

'group_by' => function($category, $key, $index) {
'group_by' => function($category, $key, $value) {
// randomly assign things into 2 groups
return rand(0, 1) == 1 ? 'Group A' : 'Group B';
},
'preferred_choices' => function($category, $key, $index) {
'preferred_choices' => function($category, $key, $value) {
return $category->getName() == 'Cat2' || $category->getName() == 'Cat3';
},
]);
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/options/choice_attr.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If an array, the keys of the ``choices`` array must be used as keys::
'Maybe' => null,
),
'choices_as_values' => true,
'choice_attr' => function($val, $key, $index) {
'choice_attr' => function($category, $key, $value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the first argument will be one of choices values true | false | null. So I think, it should be called $choiceValue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to do that change ... but then 'choice_attr' => function($choiceValue, $key, $value) is going to look confusing. choiceValue and value? What's the difference?

// adds a class like attending_yes, attending_no, etc
return ['class' => 'attending_'.strtolower($key)];
},
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/options/choice_label.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ more control::
'maybe' => null,
),
'choices_as_values' => true,
'choice_label' => function ($value, $key, $index) {
'choice_label' => function ($category, $key, $value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ($choiceValue, $key, $value).

if ($value == true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is makes more sense to check true === $choiceValue here.

return 'Definitely!';
}
Expand Down
2 changes: 1 addition & 1 deletion reference/forms/types/options/group_by.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Take the following example::
'1 month' => new \DateTime('+1 month'),
),
'choices_as_values' => true,
'group_by' => function($value, $key, $index) {
'group_by' => function($vategory, $key, $value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ($choiceValue, $key, $value).

if ($value <= new \DateTime('+3 days')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the comparison should be against the first argument $choiceValue. I will check that for 2.8. But it's definitely true for 4.0. The first argument of the callback is the model data. The third $value is just a string from request.

return 'Soon';
} else {
Expand Down