-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Keep preferred choices order in ChoiceType #30985
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
b1a9a9e
to
1516862
Compare
src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Form/ChoiceList/Factory/ChoiceListFactoryInterface.php
Outdated
Show resolved
Hide resolved
Do we need an option for that? Why not make it the only and default behavior? |
@nicolas-grekas , if that's okay from the BC prospective, I would do that. |
We have to be sure that changing the order does not break BC in some way. But I would favor this behavior if possible indeed. |
That's only a "display" order right? and the order is "random", since we don't preserve it,? |
The order is not random, it is based on the order of the original choices, ignoring the one set in the preferred choices array. |
So yeah, the behavior will change, but in a better, more controllable way. I am sure that usually people specify preferred choices in the order they expect or don't care about the order at all. I am going to do this as a default. In case we get any reasonable complaints, the BC layer would be easy. Otherwise one can just change the order of the preferred choices in the desired way and the issue is gone. |
Ok great. Note that adding an argument on a signature is a BC break. I'd suggest not making this optional and just adjust the behavior. |
Does this have to be configurable per form or would it be enough to pass an argument to the |
@xabbuh , we currently discuss to make it the only behavior. So no opt-in and no opt-out. Just change it. |
I am sure there will be complaints that some JavaScript or test breaks when the order changes. |
1516862
to
b15c028
Compare
@xabbuh , we'll see :) @HeahDude , @nicolas-grekas , ready for review! |
b15c028
to
88753ee
Compare
$otherViews | ||
); | ||
} | ||
|
||
uksort($preferredViews, static function ($a, $b) use ($preferredViewsOrder): int { | ||
return isset($preferredViewsOrder[$a], $preferredViewsOrder[$b]) |
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.
This check is needed when we have groups in preferred views.
It happens in tests and might happen in user land.
88753ee
to
340a2fb
Compare
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.
Nice to have this old feature request finally implemented!
src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php
Show resolved
Hide resolved
@xabbuh , could you review this PR, please, so that we could merge it? |
return \in_array($choice, $preferredChoices, true); | ||
// make sure we have keys that reflect order | ||
$preferredChoices = array_values($preferredChoices); | ||
$preferredChoices = static function ($choice) use ($preferredChoices) { |
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.
Hello, I'm new to reviews in symfony. Should the usage of static
be considered a BC break? It's unlikely someone relies on a Factory in preferredChoices, but possible.
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.
This closure is only used if the user didn't configure the preferred_choices
option as a callable (but as an array). And since we do not access the surrounding object context this change is fine.
Thank you @vudaltsov. |
…altsov) This PR was merged into the 4.3-dev branch. Discussion ---------- [Form] Keep preferred choices order in ChoiceType | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #5136 | License | MIT | Doc PR | todo #EUFOSSA Commits ------- 340a2fb Keep preferred_choices order
#EUFOSSA