Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] Deprecated usage of "choices" option in sub types#21919
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
UPGRADE-4.0.md Outdated
| * Using the "choices" option in``CountryType``,``CurrencyType``,``LanguageType``, | ||
| ``LocaleType``, and``TimezoneType`` is now ignored. Use the "choice_loader" option | ||
| instead or explicitly set it to``null``. |
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.
Should we really support both ways to solve it?
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.
Yes I think so, if one wants to override choices, he should not be forced to override the loader.
It makes no sense IMO to enforce lazy load something that is already loaded, if you have your choices, just pass them, do not encapsulate them in an objet that will eventually call a function to return the initial thing.
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.
@xabbuh supporting a single way to achieve it would actually involvemore work to forbid one of them. Both ways are just features of the ChoiceType: ifchoice_loader is not null, it is used. Otherwisechoices is used.
The CountryType & co currently have to do extra work to ensure that thischoices wins over thedefault choice_loader, due to BC (there was no default choice loader previously).
| 'choice_loader' =>function (Options$options) { | ||
| return$options['choices'] ?null :$this; | ||
| if ($options['choices']) { | ||
| @trigger_error(sprintf('Using "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead.',__CLASS__),E_USER_DEPRECATED); |
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.
Either we should only support thechoice_loader solution in the future or talk about the possibility to explicitly set it tonull here too.
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 hesitated, considering your comments I'd rather add it explicitly here too, thanks.
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.
Done, I've just updated the notices.
| 'choice_loader' =>function (Options$options) { | ||
| return$options['choices'] ?null :$this; | ||
| if ($options['choices']) { | ||
| @trigger_error(sprintf('Using "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.',__CLASS__),E_USER_DEPRECATED); |
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.
Using the "choices" option [...]
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.
Fixed everywhere.
| publicfunctiontestChoiceLoaderIsOverridden($type) | ||
| { | ||
| $factory = Forms::createFormFactoryBuilder() | ||
| ->addTypeExtension(newLazyChoiceTypeExtension($type)) |
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.
Do we really need the type extension here?
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 would keep it like it for consistency with the test above, and because it test both overriding the option directly and doing it with an extension, so looks safer as is.
1477302 to64ddfa1CompareHeahDude commentedMar 26, 2017
Comments addressed and rebased. Ready for final review before merging, ping @symfony/deciders. |
| Form | ||
| ------ | ||
| * Using the "choices" option in``CountryType``,``CurrencyType``,``LanguageType``, |
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 we need to reword this a bit to make clear that this is only deprecated as long as you do not set thechoice_loader option tonull (something like "using thechoices option without overriding thechoice_loader option is deprecated").
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.
Good idea! Done.
xabbuh left a comment
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.
👍
| ```php | ||
| $builder->add('custom_locales', LocaleType::class, array( | ||
| 'choices' => $availableLocales, | ||
| 'choice_loader' => null, |
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.
That doesn't look intuitive to me.
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.
Well, this is because choice_loader has priority over choices in ChoiceType (which is not documented IIRC btw)
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.
And this should not be used ideally, the ChoiceType is more accurate in such cases, I'll update the doc to clarify this.
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.
Wouldn't it be "better" to drop this example and just keep the second code snippet? And remove the recommendation to usechoice_loader as null?
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 understand this does not look pretty, but this is the actual quick fix for some breaking app.
What we can't do is to stop supporting "choices" option as it's inherited from the ChoiceType, and in such casesnull is needed because of its precedence.
What we can do is to better document these types options, and explicit that "choices" or "choice_loader" options should be overridden on a ChoiceType or an EntityType only, not on a child already doing so, unless the previous value is reused.
I would like to address your comment, but as I said in a previous outdated diff:
It makes no sense IMO to enforce lazy load something that is already loaded, if you have your choices, just pass them, do not encapsulate them in an objet that will eventually call a function to return the initial thing.
Then the real fix would be to use the ChoiceType (if the previous "choices" values is not used), I could add this instead, but objectively I would let it as is now.
I'm waiting for your final call on this symfony deciders.
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 am fine with how it is now. But we should indeed clarify the documentation about the differences of thechoices andchoice_loader options and when to use what.
fabpot commentedApr 5, 2017
Thank you@HeahDude. |
…es (HeahDude)This PR was merged into the 3.3-dev branch.Discussion----------[Form] Deprecated usage of "choices" option in sub types| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->| License | MIT| Doc PR | ~Follows#21880 and the discussion in#20771.Commits-------b5b56fc [Form] Deprecated usage of "choices" option in sub types
This PR was merged into the 3.3 branch.Discussion----------Explain how to properly override choicesUpdate the documentation forsymfony/symfony#21919. Thisfixes#7779.Commits-------a9f934e explain how to properly override choices
Follows#21880 and the discussion in#20771.