Skip to content

[Form] ChoiceType: Fix a notice when 'choices' normalizer is replaced #17406

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

Closed
wants to merge 6 commits into from

Conversation

paradajozsef
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #17270
License MIT
Doc PR -

As @gseidel mentioned, the notice only occurs, when a custom choice field added after a choice field and the custom type is expanded, and the 'choices' normalizer is replaced. The problem is that when 'choices' option is replaced, the default choiceNormalizer is not invoked. This normalizer would clear the labels from previous invocation, but it's been replaced in the custom choice type. As a result $choiceLabel normalizer will get the wrong labels because it shares the same scope with $choiceNormalizer. Resetting the label values after copy solves this problem.

@xabbuh
Copy link
Member

xabbuh commented Jan 17, 2016

Can you please add a test to avoid regressions?

@paradajozsef
Copy link
Contributor Author

@xabbuh I added a test, which covers this special case and also modified the PR comment a little bit.

@paradajozsef paradajozsef changed the title [Form] Reset choice label values after copy [Form] ChoiceType: Fix a notice when 'choices' normalizer is replaced Jan 18, 2016
@fabpot
Copy link
Member

fabpot commented Jan 19, 2016

Thank you @paradajozsef.

fabpot added a commit that referenced this pull request Jan 19, 2016
…is replaced (paradajozsef)

This PR was squashed before being merged into the 2.7 branch (closes #17406).

Discussion
----------

[Form] ChoiceType: Fix a notice when 'choices' normalizer is replaced

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17270
| License       | MIT
| Doc PR        | -

As @gseidel [mentioned](#17270 (comment)), the notice only occurs, when a custom choice field added after a choice field **and** the custom type is expanded, **and** the ```'choices'``` normalizer is replaced. The problem is that when ```'choices'``` option is replaced, the [default choiceNormalizer](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L262) is not invoked. This normalizer would [clear](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L264) the labels from previous invocation, but it's been replaced in the custom choice type. As a result [$choiceLabel](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L279) normalizer will get the wrong labels because it shares the same scope with [$choiceNormalizer](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L262). Resetting the label values after copy solves this problem.

Commits
-------

be056fd [Form] ChoiceType: Fix a notice when 'choices' normalizer is replaced
@fabpot fabpot closed this Jan 19, 2016
@paradajozsef paradajozsef deleted the form-choice-labels-fix branch January 21, 2016 08:08
fabpot added a commit that referenced this pull request Jan 21, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Form] Make tests compatible with master

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I wrote tests in this PR: #17406 which was compatible only with 2.7. @xabbuh fixed it in 2.8 and 3.0 here: #17463. And this PR fixes deprecated notices in master.

Kind of an unfortunate situation...

Commits
-------

96e40b2 Fix unit tests in master
@fabpot fabpot mentioned this pull request Feb 3, 2016
This was referenced Feb 28, 2016
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.

4 participants