-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Remove choices_as_values option on ChoiceType #16715
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
nicolas-grekas
commented
Nov 27, 2015
Q | A |
---|---|
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | - |
License | MIT |
Doc PR | - |
09e006e
to
95db512
Compare
@webmozart if you have time to review this for @nicolas-grekas, you'd be the most qualified :) |
if (true !== $choicesAsValues) { | ||
@trigger_error('The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.', E_USER_DEPRECATED); | ||
if (null !== $choicesAsValues) { | ||
@trigger_error('The "choices_as_values" option is ignored since version 3.0 and will be removed in 3.0.', 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.
"removed in 4.0"
95db512
to
32b4b19
Compare
if (true !== $choicesAsValues) { | ||
@trigger_error('The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.', E_USER_DEPRECATED); | ||
if (null !== $choicesAsValues) { | ||
@trigger_error('The "choices_as_values" option is ignored since version 3.0 and will be removed in 4.0.', 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.
@stof suggested to trigger this deprecation later in a 3.x release to be able to have bundles supporting 2.x/3.x that do not trigger deprecations
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.
Then I propose to throw an exception when this is set to false in 3.0, sounds good to you?
f0fffec
to
df2e68c
Compare
@trigger_error('The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.', E_USER_DEPRECATED); | ||
if (null !== $choicesAsValues) { | ||
if (true !== $choicesAsValues) { | ||
throw new \RuntimeException('The "choices_as_values" option must be set to true or be removed.'); |
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.
Looks good to you @Tobion?
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 just say it must not be used anymore. Saying it must be set to true when it is actually going to be deprecated will just delay a problem.
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.
But this will also confuse people. So I don't really see the point of this exception.
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.
We can't just be silent in this case, that would hide mistakes from people that would have missed an upgrade
df2e68c
to
38e8a3a
Compare
/** | ||
* @group legacy | ||
*/ | ||
public function testExpandedChoicesFlippedOptionsAreFlattened() |
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.
There are some more legacy tests related to flipped choices. Do they have to be removed 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.
yes, the diff is misleading but really only legacy tests are and should be removed 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.
oh yeah indeed
38e8a3a
to
e38dccd
Compare
@trigger_error('The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.', E_USER_DEPRECATED); | ||
if (null !== $choicesAsValues) { | ||
if (true !== $choicesAsValues) { | ||
throw new \RuntimeException('The "choices_as_values" option should not be used. Remote it and flip the contents of the "choices" option instead.'); |
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.
@Tobion message updated. Throwing the exception is important to not be silent when people keep this option to something different that "true" by mistake
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.
@nicolas-grekas Can't we use the features provided by the OptionsResolver component (especially setAllowedValues()
) for that instead of creating our own validation logic?
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 I'm not sure: we would then need to allow null
|true
, but null is not really allowed, it's only a way to know when the option is not set. Since this code path must anyway exist in 3.1 to trigger the deprecation, I think this is the closest to what we want in 3.1, thus the right way. Do you agree?
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 guess we would not need to do that if we didn't configure a default value so that the option wouldn't be set at all by default. But that's nitpicking and as we need to add this path anyway when deprecating the option, let's just keep the code as is.
e38dccd
to
06807c5
Compare
06807c5
to
ed0e26a
Compare
👍 LGTM but it would be great if @webmozart could take a look here too |
Thank you @nicolas-grekas. |
…nicolas-grekas) This PR was merged into the 3.0-dev branch. Discussion ---------- [Form] Remove choices_as_values option on ChoiceType | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- ed0e26a [Form] Remove choices_as_values option on ChoiceType