Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Nov 28, 2015

Conversation

nicolas-grekas
Copy link
Member

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

@weaverryan
Copy link
Member

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

Choose a reason for hiding this comment

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

"removed in 4.0"

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

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

Copy link
Member Author

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?

@nicolas-grekas nicolas-grekas force-pushed the master-cl branch 3 times, most recently from f0fffec to df2e68c Compare November 27, 2015 22:48
@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.');
Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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

/**
* @group legacy
*/
public function testExpandedChoicesFlippedOptionsAreFlattened()
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

oh yeah indeed

@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.');
Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

@xabbuh
Copy link
Member

xabbuh commented Nov 28, 2015

👍 LGTM but it would be great if @webmozart could take a look here too

@fabpot
Copy link
Member

fabpot commented Nov 28, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit ed0e26a into symfony:master Nov 28, 2015
fabpot added a commit that referenced this pull request Nov 28, 2015
…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
@nicolas-grekas nicolas-grekas deleted the master-cl branch November 28, 2015 10:39
@fabpot fabpot mentioned this pull request Nov 30, 2015
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.

8 participants