Skip to content

Swap $key and $index parameters in ChoiceType #9173

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

technetium
Copy link
Contributor

I've noticed the second parameter in the callback function for the
options in the ChoiceType represents the index and the third the
key.

This patch brings the documentation in line with the code.

I've noticed the second parameter in the callback function for the
options in the ChoiceType represents the index and the third the
key.

This patch brings the documentation in line with the code.
@xabbuh xabbuh added this to the 2.7 milestone Jan 31, 2018
@xabbuh xabbuh added the Form label Jan 31, 2018
@javiereguiluz
Copy link
Member

@vudaltsov can you please review if this proposal is correct? Thanks!

@@ -92,19 +92,18 @@ method::
new Category('Cat3'),
new Category('Cat4'),
],
'choice_label' => function($category, $key, $index) {
'choice_label' => function($category, $index, $key) {
Copy link
Member

Choose a reason for hiding this comment

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

function($category, $key, $value)

/** @var Category $category */
return strtoupper($category->getName());
},
'choice_attr' => function($category, $key, $index) {
'choice_attr' => function($category, $index, $key) {
Copy link
Member

Choose a reason for hiding this comment

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

function($category, $key, $value)

return ['class' => 'category_'.strtolower($category->getName())];
},

'group_by' => function($category, $key, $index) {
'group_by' => function($category, $index, $key) {
Copy link
Member

Choose a reason for hiding this comment

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

function($category, $key, $value)

@@ -18,7 +18,7 @@ If an array, the keys of the ``choices`` array must be used as keys::
'No' => false,
'Maybe' => null,
),
'choice_attr' => function($val, $key, $index) {
'choice_attr' => function($val, $index, $key) {
Copy link
Member

Choose a reason for hiding this comment

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

function($category, $key, $value)

@@ -16,7 +16,7 @@ more control::
'no' => false,
'maybe' => null,
),
'choice_label' => function ($value, $key, $index) {
'choice_label' => function ($value, $index, $key) {
Copy link
Member

Choose a reason for hiding this comment

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

function($category, $key, $value)

@@ -22,7 +22,7 @@ Take the following example::
'1 week' => new \DateTime('+1 week'),
'1 month' => new \DateTime('+1 month')
),
'group_by' => function($val, $key, $index) {
'group_by' => function($val, $index, $key) {
Copy link
Member

Choose a reason for hiding this comment

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

function($category, $key, $value)

Copy link
Contributor

@vudaltsov vudaltsov left a comment

Choose a reason for hiding this comment

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

Agree with @xabbuh, 2 and 3 arguments should be named $key and $value, the first argument should be named according to choice data.

@javiereguiluz
Copy link
Member

I'm afraid this PR stalled and now it has some conflicts. So I've opened #9835 to finish it. Thanks @technetium for opening this and thanks to reviewers.

javiereguiluz added a commit that referenced this pull request May 29, 2018
This PR was squashed before being merged into the 2.8 branch (closes #9835).

Discussion
----------

Fixed the params in ChoiceType methods

This finishes #9173.

Commits
-------

b14cf70 Fixed the params in ChoiceType methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants