Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:masterfromHeahDude:bc/choice-types
Apr 5, 2017

Conversation

@HeahDude
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets#...
LicenseMIT
Doc PR~

Follows#21880 and the discussion in#20771.


* 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``.
Copy link
Member

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?

Copy link
ContributorAuthor

@HeahDudeHeahDudeMar 8, 2017
edited
Loading

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.

xabbuh reacted with thumbs up emoji
Copy link
Member

@stofstofMar 8, 2017
edited
Loading

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).

HeahDude, xabbuh, and yceruto reacted with thumbs up emoji
'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);
Copy link
Member

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.

Copy link
ContributorAuthor

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.

xabbuh reacted with thumbs up emoji
Copy link
ContributorAuthor

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);
Copy link
Member

Choose a reason for hiding this comment

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

Using the "choices" option [...]

Copy link
ContributorAuthor

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))
Copy link
Member

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?

Copy link
ContributorAuthor

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.

@nicolas-grekasnicolas-grekas added this to the3.3 milestoneMar 10, 2017
@HeahDudeHeahDudeforce-pushed thebc/choice-types branch 2 times, most recently from1477302 to64ddfa1CompareMarch 26, 2017 20:52
@HeahDude
Copy link
ContributorAuthor

Comments addressed and rebased. Ready for final review before merging, ping @symfony/deciders.

Form
------

* Using the "choices" option in``CountryType``,``CurrencyType``,``LanguageType``,
Copy link
Member

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").

HeahDude reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good idea! Done.

Copy link
Member

@xabbuhxabbuh left a 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,
Copy link
Contributor

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.

Copy link
Member

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)

Copy link
ContributorAuthor

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.

Copy link
Member

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?

Copy link
ContributorAuthor

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.

Copy link
Member

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
Copy link
Member

Thank you@HeahDude.

@fabpotfabpot merged commitb5b56fc intosymfony:masterApr 5, 2017
fabpot added a commit that referenced this pull requestApr 5, 2017
…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
@HeahDudeHeahDude deleted the bc/choice-types branchApril 5, 2017 21:00
@HeahDudeHeahDude restored the bc/choice-types branchApril 23, 2017 08:39
@HeahDudeHeahDude deleted the bc/choice-types branchApril 23, 2017 08:39
@fabpotfabpot mentioned this pull requestMay 1, 2017
xabbuh added a commit to symfony/symfony-docs that referenced this pull requestJun 10, 2017
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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof left review comments

@xabbuhxabbuhxabbuh approved these changes

+1 more reviewer

@TobionTobionTobion left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

7 participants

@HeahDude@fabpot@stof@Tobion@xabbuh@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp