-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fixed the params in ChoiceType methods #9835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -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) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
@@ -20,7 +20,7 @@ more control:: | |||
'maybe' => null, | |||
), | |||
'choices_as_values' => true, | |||
'choice_label' => function ($value, $key, $index) { | |||
'choice_label' => function ($category, $key, $value) { |
There was a problem hiding this comment.
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)
.
@@ -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) { |
There was a problem hiding this comment.
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)
.
@@ -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) { | |||
if ($value <= new \DateTime('+3 days')) { |
There was a problem hiding this comment.
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.
reference/forms/types/choice.rst
Outdated
/** @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())]; | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, found some other things that could be fixed in this PR. And some other improvements I will do in a new one.
@@ -20,7 +20,7 @@ more control:: | |||
'maybe' => null, | |||
), | |||
'choices_as_values' => true, | |||
'choice_label' => function ($value, $key, $index) { | |||
'choice_label' => function ($choiceValue, $key, $value) { | |||
if ($value == true) { |
There was a problem hiding this comment.
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.
@javiereguiluz , let's finish this? :) @xabbuh , could you review this PR, please? |
@vudaltsov I thought you were going to create a new PR instead of this one ... so I was waiting :) I'm going to finish and merge this so you can create a new PR. Thanks! |
This is now merged! @vudaltsov when you create your PR, please make any change needed to create variables easy to understand. E.g. |
I think that |
@vudaltsov what about just |
@yceruto , okay! I will do that in my PR. |
I still think it's not understandable. I can't understand anything here --> Please, let's pick variable names that the reader cannot mistake. For example, which of the following names best describe the previous arguments? function ($selectedChoice, $choiceIndex, $choiceValue)
function ($availableChoice, $selectedIndex, $selectedValue)
function ($availableChoice, $choiceIndex, $choiceValue)
etc. |
|
So |
@javiereguiluz , I gave a wrong explanation. The third argument is not the selected value. This callback will be called for all choices. So we are not talking about user here - the submit has not happened yet. The third argument is how the choice is represented in a view in |
What about this: |
or... |
The problem with |
Well, I think it's better explain each argument below the first example so. |
This finishes #9173.