8000 [Form] Deprecate "choices_as_values" => false · Issue #14951 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Deprecate "choices_as_values" => false #14951

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
webmozart opened this issue Jun 11, 2015 · 5 comments
Closed

[Form] Deprecate "choices_as_values" => false #14951

webmozart opened this issue Jun 11, 2015 · 5 comments
Labels
Form Good first issue Ideal for your first contribution! (some Symfony experience may be required)

Comments

@webmozart
Copy link
Contributor

The value false for the "choices_as_values" option (= the current default value) should be deprecated in 2.8. This means that people need to manually set the option to true for all choice fields.

In Symfony 3.0, we can remove the code for handling the value false and deprecate the "choices_as_values" option altogether. In a future 3.x release, the option can be removed to complete the transition.

@webmozart webmozart added Form Good first issue Ideal for your first contribution! (some Symfony experience may be required) labels Jun 11, 2015
@webmozart
Copy link
Contributor Author

See #14825 for more discussion on the motivation behind deprecating the option.

@soullivaneuh
Copy link
Contributor

Well, to continue here, I would 👎 for this.

To resume why, just read @xabbuh say:

@webmozart Maybe we should just provide an option that sets choice_label to function ($choice) { return $choice; }. Shouldn't be that hard to maintain in the component, but saves developers to write cumbersome and boring code.

@stof
Copy link
Member
stof commented Jun 12, 2015

@soullivaneuh choices_as_values is not directly to choice_label. So you are talking about a different topic.
choices_as_values controls where the choices are the keys or the values in the choices option. Symfony 2.0 shipped with choices as keys (and labels as values), which means that the easy syntax only works when your choices are integers or strings. Any other case (boolean choices for instance) required passing a ChoiceList object instead, making the usage more complex (especially for people forgetting that booleans cannot be used as keys as PHP just casts them to string silently).
This is the reason why this option has been introduced in 2.7 to be able to flip the array (while maintaining BC). the advantage is that any type of data can be used in this way (strings, integers, floats, booleans, objects, arrays)

@webmozart
Copy link
Contributor Author

@stof He is talking about choice_value.

@xabbuh
Copy link
Member
xabbuh commented Nov 1, 2015

@webmozart Is this something you think we still need to consider for 2.8?

fabpot added a commit that referenced this issue 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 fabpot closed this as completed Nov 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Form Good first issue Ideal for your first contribution! (some Symfony experience may be required)
Projects
None yet
Development

No branches or pull requests

5 participants
0