Skip to content
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

Remove choices as values in 3.0 #6459

Merged
merged 1 commit into from
May 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 3 additions & 36 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
| | - `choice_name`_ |
| | - `choice_translation_domain`_ |
| | - `choice_value`_ |
| | - `choices_as_values`_ |
| | - `choices_as_values`_ (deprecated) |
Copy link
Contributor

Choose a reason for hiding this comment

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

It is deprecated as of 3.1, not removed :)

| | - `expanded`_ |
| | - `group_by`_ |
| | - `multiple`_ |
Expand Down Expand Up @@ -167,8 +167,6 @@ is the item's label and the array value is the item's value::

$builder->add('inStock', ChoiceType::class, array(
'choices' => array('In Stock' => true, 'Out of Stock' => false),
// always include this
'choices_as_values' => true,
));

.. include:: /reference/forms/types/options/choice_attr.rst.inc
Expand All @@ -195,39 +193,8 @@ would replace the ``choices`` option.
choices_as_values
~~~~~~~~~~~~~~~~~

**type**: ``boolean`` **default**: false

The ``choices_as_values`` option was added to keep backward compatibility with the
*old* way of handling the ``choices`` option. When set to ``false`` (or omitted),
the choice keys are used as the underlying value and the choice values are shown
to the user.

* Before 2.7 (and deprecated now)::

$builder->add('gender', 'choice', array(
// Shows "Male" to the user, returns "m" when selected
'choices' => array('m' => 'Male', 'f' => 'Female'),
// before 2.7, this option didn't actually exist, but the
// behavior was equivalent to setting this to false in 2.7.
'choices_as_values' => false,
));

* Since 2.7::

$builder->add('gender', ChoiceType::class, array(
// Shows "Male" to the user, returns "m" when selected
'choices' => array('Male' => 'm', 'Female' => 'f'),
'choices_as_values' => true,
));

In Symfony 3.0, the ``choices_as_values`` option doesn't exist, but the ``choice``
type behaves as if it were set to true:

* Default for 3.0::

$builder->add('gender', ChoiceType::class, array(
'choices' => array('Male' => 'm', 'Female' => 'f'),
));
This option is deprecated and you should remove it from your 3.x projects (removing
it will have *no* effect). For its purpose in 2.x, see the 2.7 documentation.

.. include:: /reference/forms/types/options/expanded.rst.inc

Expand Down
1 change: 0 additions & 1 deletion reference/forms/types/options/choice_attr.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ If an array, the keys of the ``choices`` array must be used as keys::
'No' => false,
'Maybe' => null,
),
'choices_as_values' => true,
'choice_attr' => function($val, $key, $index) {
// adds a class like attending_yes, attending_no, etc
return ['class' => 'attending_'.strtolower($key)];
Expand Down
2 changes: 0 additions & 2 deletions reference/forms/types/options/choice_label.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ more control::
'no' => false,
'maybe' => null,
),
'choices_as_values' => true,
'choice_label' => function ($value, $key, $index) {
if ($value == true) {
return 'Definitely!';
Expand Down Expand Up @@ -48,7 +47,6 @@ If your choice values are objects, then ``choice_label`` can also be a
new Status(Status::NO),
new Status(Status::MAYBE),
),
'choices_as_values' => true,
'choice_label' => 'displayName',
));

Expand Down
1 change: 0 additions & 1 deletion reference/forms/types/options/group_by.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Take the following example::
'1 week' => new \DateTime('+1 week'),
'1 month' => new \DateTime('+1 month')
),
'choices_as_values' => true,
'group_by' => function($val, $key, $index) {
if ($val <= new \DateTime('+3 days')) {
return 'Soon';
Expand Down
2 changes: 0 additions & 2 deletions reference/forms/types/options/preferred_choices.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ you can list the most popular on top, like Bork Bork and Pirate::
'Bork' => 'muppets',
'Pirate' => 'arr'
),
'choices_as_values' => true,
'preferred_choices' => array('muppets', 'arr')
));

Expand All @@ -34,7 +33,6 @@ be especially useful if your values are objects::
'1 week' => new \DateTime('+1 week'),
'1 month' => new \DateTime('+1 month')
),
'choices_as_values' => true,
'preferred_choices' => function ($val, $key) {
// prefer options within 3 days
return $val <= new \DateTime('+3 days');
Expand Down