Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Form] Add the docs for EnumType#16127
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,6 +23,7 @@ Form Types Reference | ||
| types/color | ||
| types/choice | ||
| types/enum | ||
| types/entity | ||
| types/country | ||
| types/language | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| .. index:: | ||
| single: Forms; Fields; EnumType | ||
| EnumType Field | ||
| ============== | ||
| .. versionadded:: 5.4 | ||
| The ``EnumType`` form field was introduced in Symfony 5.4. | ||
| A multi-purpose field used to allow the user to "choose" one or more options | ||
| defined in a `PHP enumeration`_. It extends the :doc:`ChoiceType </refernce/forms/types/enum>` | ||
| field and defines the same options. | ||
| +---------------------------+----------------------------------------------------------------------+ | ||
| | Rendered as | can be various tags (see below) | | ||
| +---------------------------+----------------------------------------------------------------------+ | ||
| | Default invalid message | The selected choice is invalid. | | ||
| +---------------------------+----------------------------------------------------------------------+ | ||
| | Legacy invalid message | The value {{ value }} is not valid. | | ||
| +---------------------------+----------------------------------------------------------------------+ | ||
| | Parent type | :doc:`ChoiceType </reference/forms/types/choice>` | | ||
| +---------------------------+----------------------------------------------------------------------+ | ||
| | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\EnumType` | | ||
| +---------------------------+----------------------------------------------------------------------+ | ||
| .. include:: /reference/forms/types/options/_debug_form.rst.inc | ||
| Example Usage | ||
| ------------- | ||
| Before using this field, you'll need to have some PHP enumeration (or "enum" for | ||
| short) defined somewhere in your application. This enum has to be of type | ||
| "backed enum", where each keyword defines a scalar value such a string:: | ||
| // src/Config/TextAlign.php | ||
| namespace App\Config; | ||
| enum TextAlign | ||
| { | ||
| case Left = 'Left/Start aligned'; | ||
| case Center = 'Center/Middle aligned'; | ||
| case Right = 'Right/End aligned'; | ||
| } | ||
| Instead of using the values of the enumeration in a ``choices`` option, the | ||
| ``EnumType`` only requires to define the ``class`` option pointing to the enum:: | ||
| use App\Config\TextAlign; | ||
| use Symfony\Component\Form\Extension\Core\Type\EnumType; | ||
| // ... | ||
| $builder->add('alignment', EnumType::class, ['class' => TextAlign::class]); | ||
| This will display a ``<select>`` tag with the three possible values defined in | ||
| the ``TextAlign`` enum. Use the ``expanded`` and ``multiple`` options to display | ||
| these values as ``<input type="checkbox">`` and ``<input type="radio">``. | ||
| Field Options | ||
| ------------- | ||
| class | ||
| ~~~~~ | ||
| **type**: ``string`` **default**: (it has no default) | ||
| The fully-qualified class name (FQCN) of the PHP enum used to get the values | ||
| displayed by this form field. | ||
| Inherited Options | ||
| ----------------- | ||
| These options inherit from the :doc:`ChoiceType </reference/forms/types/choice>`: | ||
| .. include:: /reference/forms/types/options/error_bubbling.rst.inc | ||
| .. include:: /reference/forms/types/options/error_mapping.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 | ||
| .. include:: /reference/forms/types/options/choice_type_trim.rst.inc | ||
| These options inherit from the :doc:`FormType </reference/forms/types/form>`: | ||
| .. include:: /reference/forms/types/options/attr.rst.inc | ||
| .. include:: /reference/forms/types/options/data.rst.inc | ||
| .. include:: /reference/forms/types/options/disabled.rst.inc | ||
| .. include:: /reference/forms/types/options/empty_data_declaration.rst.inc | ||
| .. include:: /reference/forms/types/options/empty_data_description.rst.inc | ||
| .. include:: /reference/forms/types/options/help.rst.inc | ||
| .. include:: /reference/forms/types/options/help_attr.rst.inc | ||
| .. include:: /reference/forms/types/options/help_html.rst.inc | ||
| .. include:: /reference/forms/types/options/label.rst.inc | ||
| .. include:: /reference/forms/types/options/label_attr.rst.inc | ||
| .. include:: /reference/forms/types/options/label_format.rst.inc | ||
| .. include:: /reference/forms/types/options/mapped.rst.inc | ||
| .. include:: /reference/forms/types/options/required.rst.inc | ||
| .. include:: /reference/forms/types/options/row_attr.rst.inc | ||
| .. _`PHP enumeration`: https://wiki.php.net/rfc/enumerations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.