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

Skip to content

[Form] Deprecated setting "choices_as_values" to "false" #16681

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

Conversation

webmozart
Copy link
Contributor

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

This PR does two important things that were forgot in the 2.7 branch:

  • The value false of the choices_as_values option was deprecated, but the deprecation error was missing. This error was added now. The option should be set to true, the entries of the corresponding choices option should be flipped. In 2.8, the choices_as_values option will be deprecated entirely.
  • When setting choices_as_values to true, the generated HTML values of choices always fell back to 0, 1, …, even when the choices can be converted to duplicate-free strings. This is fixed now: The HTML values now equal the string cast of the choices whenever possible to match the <2.7 behavior.

@webmozart webmozart force-pushed the choices-as-values-deprecation branch from 1176ba1 to d13a042 Compare November 26, 2015 10:58
@@ -110,7 +110,7 @@ Form

* You should flip the keys and values of the "choices" option in ChoiceType
and set the "choices_as_values" option to `true`. The default value of that
option will be switched to `true` in Symfony 3.0.
option will be switched to `true` in Symfony 2.8.
Copy link
Member

Choose a reason for hiding this comment

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

changing this in 2.8 would be a bc break isn't it? it has to be in 3.0

@webmozart webmozart force-pushed the choices-as-values-deprecation branch from d13a042 to c7b1ce7 Compare November 26, 2015 17:05
@webmozart webmozart force-pushed the choices-as-values-deprecation branch 3 times, most recently from e94870e to 76f4e6c Compare November 26, 2015 17:29
@nicolas-grekas
Copy link
Member

👍

*/
private static function getFlippedTimezones()
{
if (null === static::$timezones) {
Copy link
Member

Choose a reason for hiding this comment

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

this must use self:: to access private properties, not static::. Otherwise the code is broken when extending the class (as it would try to access the property on the child class, where it is not there)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed.

@stof
Copy link
Member

stof commented Nov 26, 2015

IMO, this needs to be done in 2.8, not in 2.7. Existing 2.7 projects running without deprecation warnings should not get such new warning in the next patch release.
We already followed this policy in the past

@nicolas-grekas
Copy link
Member

@stof only the deprecation triggering part then. The code should really remain here.

@stof
Copy link
Member

stof commented Nov 26, 2015

In 2.8, the choices_as_values option will be deprecated entirely.

This is not possible, as it would mean that it is impossible to write code working on 2.8 and 3.0 without deprecation notices.
In 2.7+, you are forced to pass it to use the new way. This means that we need to keep the option in 3.0 (making it a no-op), so that 2.8 code continues to work (because passing unknown options is forbidden)
This option can only be deprecated later in the 3.x lifetime (the ideal time would be after the 2.8 EOL, so that bundle supporting the 2.8 LTS can run deprecation-free and bundles requiring 3+ can simply omit it)

@webmozart
Copy link
Contributor Author

@stof The option was already deprecated (check the UPGRADE file), but the deprecation error was missing. The upgrade path is:

2.7: choices_as_values=false is deprecated, you should set it to true
3.0: choices_as_values=false is unsupported, choices_as_values=true is deprecated
4.0: choices_as_values is removed

We can also switch the first step to 2.8 if you prefer that.

@stof
Copy link
Member

stof commented Nov 26, 2015

@webmozart in case we forgot deprecation warnings in 2.7 before the release, they have been added in 2.8 in the past. So the deprecation warning should go in 2.8

@webmozart webmozart force-pushed the choices-as-values-deprecation branch from 4a040f9 to 721d09f Compare November 26, 2015 18:00
@webmozart
Copy link
Contributor Author

@stof Ok. I changed the deprecation message to 2.8. Let's merge this into 2.8.

@fabpot
Copy link
Member

fabpot commented Nov 27, 2015

Thank you @webmozart.

@fabpot fabpot closed this Nov 27, 2015
fabpot added a commit that referenced this pull request Nov 27, 2015
…webmozart)

This PR was submitted for the 2.7 branch but it was merged into the 2.8 branch instead (closes #16681).

Discussion
----------

[Form] Deprecated setting "choices_as_values" to "false"

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

This PR does two important things that were forgot in the 2.7 branch:

* The value `false` of the `choices_as_values` option was deprecated, but the deprecation error was missing. This error was added now. The option should be set to `true`, the entries of the corresponding `choices` option should be flipped. In 2.8, the `choices_as_values` option will be deprecated entirely.

* When setting `choices_as_values` to `true`, the generated HTML values of choices always fell back to `0`, `1`, …, even when the choices can be converted to duplicate-free strings. This is fixed now: The HTML values now equal the string cast of the choices whenever possible to match the <2.7 behavior.

Commits
-------

5d7678e [Form] Deprecated setting "choices_as_values" to "false"
fabpot added a commit that referenced this pull request Nov 27, 2015
…art)

This PR was merged into the 2.8 branch.

Discussion
----------

[Form] Deprecated TimezoneType::getTimezones()

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

This method is useless as of #16681. It needs to be deprecated before we can remove it since it is public.

Commits
-------

41df3fc [Form] Deprecated TimezoneType::getTimezones()
fabpot added a commit to symfony/form that referenced this pull request Nov 27, 2015
…art)

This PR was merged into the 2.8 branch.

Discussion
----------

[Form] Deprecated TimezoneType::getTimezones()

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

This method is useless as of symfony/symfony#16681. It needs to be deprecated before we can remove it since it is public.

Commits
-------

41df3fc [Form] Deprecated TimezoneType::getTimezones()
fabpot added a commit that referenced this pull request Nov 27, 2015
…webmozart)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] Deprecated setting "choices_as_values" to "false"

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

This is #16681 for 2.7, i.e. without the deprecations trigger

Commits
-------

3ab8189 [Form] Deprecated setting "choices_as_values" to "false"
fabpot added a commit to symfony/form that referenced this pull request Nov 27, 2015
…art)

This PR was merged into the 2.8 branch.

Discussion
----------

[Form] Deprecated TimezoneType::getTimezones()

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

This method is useless as of symfony/symfony#16681. It needs to be deprecated before we can remove it since it is public.

Commits
-------

41df3fc [Form] Deprecated TimezoneType::getTimezones()
@peterrehm
Copy link
Contributor

@webmozart If I am looking at your upgrade path wouldn't it make sense to set choices_as_values to true by default in 2.8 or is this a BC break. If so will it be true in 3.0?

@weaverryan
Copy link
Member

@peterrehm see #16715. The option exists in 3.0, but is ignored, and the behavior acts as if it's set to true. So you'll set choices_as_values to true in 2.8, upgrade to 3.0, then remove the option.

This was referenced Nov 30, 2015
nicolas-grekas added a commit that referenced this pull request Dec 18, 2015
This PR was merged into the 2.8 branch.

Discussion
----------

Upgrade information for the choice_value option

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

Relates to #14825 and #14377. The behaviour was changed with #16681 so a not in the upgrade information makes sense to me.

Commits
-------

28675c9 Reflected the change of the choice_value option in the Upgrade information
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.

7 participants