Skip to content

choices_as_values references removed #6473

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
wants to merge 1 commit into from
Closed
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
choices_as_values references removed
  • Loading branch information
dossorio committed Apr 14, 2016
commit a2f98f2c26ba1e93a0138b9ff89cb184c337f189
44 changes: 0 additions & 44 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
| | - `choice_name`_ |
| | - `choice_translation_domain`_ |
| | - `choice_value`_ |
| | - `choices_as_values`_ |
| | - `expanded`_ |
| | - `group_by`_ |
| | - `multiple`_ |
Expand Down Expand Up @@ -167,8 +166,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 @@ -192,47 +189,6 @@ would replace the ``choices`` option.

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

choices_as_values
~~~~~~~~~~~~~~~~~

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

.. versionadded:: 2.7

The ``choices_as_values`` option was introduced in Symfony 2.7.

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'),
));

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

.. include:: /reference/forms/types/options/group_by.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