Skip to content

Commit

Permalink
minor #6262 [Form] reorder options in choice types references (HeahDude)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

[Form] reorder options in choice types references

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.7+
| Fixed tickets | #6261

Commits
-------

3eda649 reorder options in choice types references
  • Loading branch information
xabbuh committed Feb 12, 2016
2 parents ebe0724 + 3eda649 commit bc70d00
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 94 deletions.
157 changes: 78 additions & 79 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
| Rendered as | can be various tags (see below) |
+-------------+------------------------------------------------------------------------------+
| Options | - `choices`_ |
| | - `choices_as_values`_ |
| | - `choice_loader`_ |
| | - `choice_label`_ |
| | - `choice_attr`_ |
| | - `choice_label`_ |
| | - `choice_list`_ (deprecated) |
| | - `choice_loader`_ |
| | - `choice_name`_ |
| | - `choice_translation_domain`_ |
| | - `placeholder`_ |
| | - `choice_value`_ |
| | - `choices_as_values`_ |
| | - `expanded`_ |
| | - `group_by`_ |
| | - `multiple`_ |
| | - `placeholder`_ |
| | - `preferred_choices`_ |
| | - `group_by`_ |
| | - `choice_value`_ |
| | - `choice_name`_ |
| | - `choice_list`_ (deprecated) |
+-------------+------------------------------------------------------------------------------+
| Overridden | - `compound`_ |
| options | - `empty_data`_ |
Expand Down Expand Up @@ -172,6 +172,73 @@ is the item's label and the array value is the item's value::
'choices_as_values' => true,
));

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

.. _reference-form-choice-label:

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

choice_list
~~~~~~~~~~~

.. caution::

The ``choice_list`` option of ChoiceType was deprecated in Symfony 2.7.
You should use `choices`_ or `choice_loader`_ now.

**type**: :class:`Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface`

This is one way of specifying the options to be used for this field.
The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
For more advanced cases, a custom class that implements the interface
can be created to supply the choices.

With this option you can also allow float values to be selected as data.
For example::

use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;

// ...
$builder->add('status', 'choice', array(
'choice_list' => new ChoiceList(
array(1, 0.5, 0.1),
array('Full', 'Half', 'Almost empty')
)
));

The ``status`` field created by the code above will be rendered as:

.. code-block:: html

<select name="status">
<option value="0">Full</option>
<option value="1">Half</option>
<option value="2">Almost empty</option>
</select>

But don't be confused! If ``Full`` is selected (value ``0`` in HTML), ``1``
will be returned in your form. If ``Almost empty`` is selected (value ``2``
in HTML), ``0.1`` will be returned.

choice_loader
~~~~~~~~~~~~~

.. versionadded:: 2.7

The ``choice_loader`` option was added in Symfony 2.7.

**type**: :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\ChoiceLoaderInterface`

The ``choice_loader`` can be used to only partially load the choices in cases where
a fully-loaded list is not necessary. This is only needed in advanced cases and
would replace the ``choices`` option.

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

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

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

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

Expand Down Expand Up @@ -213,83 +280,15 @@ type behaves as if it were set to true:
'choices' => array('Male' => 'm', 'Female' => 'f'),
));

choice_loader
~~~~~~~~~~~~~

.. versionadded:: 2.7

The ``choice_loader`` option was added in Symfony 2.7.

**type**: :class:`Symfony\\Component\\Form\\ChoiceList\\Loader\\ChoiceLoaderInterface`

The ``choice_loader`` can be used to only partially load the choices in cases where
a fully-loaded list is not necessary. This is only needed in advanced cases and
would replace the ``choices`` option.

.. _reference-form-choice-label:

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

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

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

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

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

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

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

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

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

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


choice_list
~~~~~~~~~~~

.. caution::

The ``choice_list`` option of ChoiceType was deprecated in Symfony 2.7.
You should use `choices`_ or `choice_loader`_ now.

**type**: :class:`Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceListInterface`

This is one way of specifying the options to be used for this field.
The ``choice_list`` option must be an instance of the ``ChoiceListInterface``.
For more advanced cases, a custom class that implements the interface
can be created to supply the choices.

With this option you can also allow float values to be selected as data.
For example::

use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;

// ...
$builder->add('status', 'choice', array(
'choice_list' => new ChoiceList(
array(1, 0.5, 0.1),
array('Full', 'Half', 'Almost empty')
)
));

The ``status`` field created by the code above will be rendered as:

.. code-block:: html
.. include:: /reference/forms/types/options/multiple.rst.inc

<select name="status">
<option value="0">Full</option>
<option value="1">Half</option>
<option value="2">Almost empty</option>
</select>
.. include:: /reference/forms/types/options/placeholder.rst.inc

But don't be confused! If ``Full`` is selected (value ``0`` in HTML), ``1``
will be returned in your form. If ``Almost empty`` is selected (value ``2``
in HTML), ``0.1`` will be returned.
.. include:: /reference/forms/types/options/preferred_choices.rst.inc

Overridden Options
------------------
Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/country.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ you should just use the ``choice`` type directly.
+-------------+-----------------------------------------------------------------------+
| Inherited | from the :doc:`choice </reference/forms/types/choice>` type |
| options | |
| | - `placeholder`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `expanded`_ |
| | - `multiple`_ |
| | - `placeholder`_ |
| | - `preferred_choices`_ |
| | |
| | from the :doc:`form </reference/forms/types/form>` type |
Expand Down Expand Up @@ -68,8 +68,6 @@ Inherited Options
These options inherit from the :doc:`choice </reference/forms/types/choice>`
type:

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

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

.. include:: /reference/forms/types/options/error_mapping.rst.inc
Expand All @@ -78,6 +76,8 @@ type:

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

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

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

These options inherit from the :doc:`form </reference/forms/types/form>`
Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/currency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ you should just use the ``choice`` type directly.
+-------------+------------------------------------------------------------------------+
| Inherited | from the :doc:`choice </reference/forms/types/choice>` type |
| options | |
| | - `placeholder`_ |
| | - `error_bubbling`_ |
| | - `expanded`_ |
| | - `multiple`_ |
| | - `placeholder`_ |
| | - `preferred_choices`_ |
| | |
| | from the :doc:`form </reference/forms/types/form>` type |
Expand Down Expand Up @@ -60,14 +60,14 @@ Inherited Options
These options inherit from the :doc:`choice</reference/forms/types/choice>`
type:

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

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

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

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

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

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

These options inherit from the :doc:`form</reference/forms/types/form>`
Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ you should just use the ``choice`` type directly.
+-------------+------------------------------------------------------------------------+
| Inherited | from the :doc:`choice </reference/forms/types/choice>` type |
| options | |
| | - `placeholder`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `expanded`_ |
| | - `multiple`_ |
| | - `placeholder`_ |
| | - `preferred_choices`_ |
| | |
| | from the :doc:`form </reference/forms/types/form>` type |
Expand Down Expand Up @@ -69,8 +69,6 @@ Inherited Options
These options inherit from the :doc:`choice </reference/forms/types/choice>`
type:

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

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

.. include:: /reference/forms/types/options/error_mapping.rst.inc
Expand All @@ -79,6 +77,8 @@ type:

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

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

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

These options inherit from the :doc:`form </reference/forms/types/form>`
Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/locale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ you should just use the ``choice`` type directly.
+-------------+------------------------------------------------------------------------+
| Inherited | from the :doc:`choice </reference/forms/types/choice>` type |
| options | |
| | - `placeholder`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `expanded`_ |
| | - `multiple`_ |
| | - `placeholder`_ |
| | - `preferred_choices`_ |
| | |
| | from the :doc:`form </reference/forms/types/form>` type |
Expand Down Expand Up @@ -71,8 +71,6 @@ Inherited Options
These options inherit from the :doc:`choice </reference/forms/types/choice>`
type:

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

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

.. include:: /reference/forms/types/options/error_mapping.rst.inc
Expand All @@ -81,6 +79,8 @@ type:

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

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

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

These options inherit from the :doc:`form </reference/forms/types/form>`
Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/timezone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ you should just use the ``choice`` type directly.
+-------------+------------------------------------------------------------------------+
| Inherited | from the :doc:`choice </reference/forms/types/choice>` type |
| options | |
| | - `placeholder`_ |
| | - `expanded`_ |
| | - `multiple`_ |
| | - `placeholder`_ |
| | - `preferred_choices`_ |
| | |
| | from the :doc:`form </reference/forms/types/form>` type |
Expand Down Expand Up @@ -64,12 +64,12 @@ Inherited Options
These options inherit from the :doc:`choice </reference/forms/types/choice>`
type:

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

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

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

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

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

These options inherit from the :doc:`form </reference/forms/types/form>`
Expand Down

0 comments on commit bc70d00

Please sign in to comment.