Skip to content

Documented label_format option #4489

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
3 changes: 3 additions & 0 deletions reference/forms/types/checkbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ if the box is unchecked, the value will be set to false.
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -70,6 +71,8 @@ These options inherit from the :doc:`form </reference/forms/types/form>` type:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ option.
| | - `inherit_data`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -180,6 +181,8 @@ These options inherit from the :doc:`form </reference/forms/types/form>` type:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ forms, which is useful when creating forms that expose one-to-many relationships
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `required`_ |
+-------------+-----------------------------------------------------------------------------+
Expand Down Expand Up @@ -383,6 +384,8 @@ error_bubbling

.. 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
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/country.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ you should just use the ``choice`` type directly.
| | - `empty_data`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -100,6 +101,8 @@ The actual default value of this option depends on other field options:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/currency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ should just use the ``choice`` type directly.
| | - `empty_data`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -90,6 +91,8 @@ The actual default value of this option depends on other field options:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The ``email`` field is a text field that is rendered using the HTML5
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `max_length`_ (deprecated as of 2.5) |
| | - `read_only`_ |
Expand Down Expand Up @@ -53,6 +54,8 @@ The default value is ``''`` (the empty string).

.. 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/max_length.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/entity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ objects from the database.
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -240,6 +241,8 @@ The actual default value of this option depends on other field options:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The ``file`` type represents a file input in your form.
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -116,6 +117,8 @@ The default value is ``null``.

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on all types for which ``form`` is the parent type.
| | - `invalid_message`_ |
| | - `invalid_message_parameters`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `max_length`_ (deprecated as of 2.5) |
| | - `method`_ |
Expand Down Expand Up @@ -94,6 +95,8 @@ The actual default value of this option depends on other field options:

.. 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

.. _reference-form-option-max_length:
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/integer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ integers. By default, all non-integer values (e.g. 6.78) will round down (e.g. 6
| | - `invalid_message_parameters`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -102,6 +103,8 @@ The default value is ``''`` (the empty string).

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ you should just use the ``choice`` type directly.
| | - `empty_data`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -101,6 +102,8 @@ The actual default value of this option depends on other field options:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/locale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ you should just use the ``choice`` type directly.
| | - `empty_data`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -103,6 +104,8 @@ The actual default value of this option depends on other field options:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/money.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ how the input and output of the data is handled.
| | - `invalid_message_parameters`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -112,6 +113,8 @@ The default value is ``''`` (the empty string).

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/number.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ you want to use for your number.
| | - `invalid_message_parameters`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -98,6 +99,8 @@ The default value is ``''`` (the empty string).

.. 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/read_only.rst.inc
Expand Down
30 changes: 30 additions & 0 deletions reference/forms/types/options/label_format.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
label_format
~~~~~~~~~~~~

.. versionadded:: 2.6
The ``label_format`` option was introduced in Symfony 2.6.

**type**: ``string`` **default**: ``null``

This allows to change the label for a field. You have access to 2 variables:
``%name%`` and ```%id%``. The ``%id%`` is unique for each field and contains
the complete path to and the field name, the ``%name%`` contains just the field
name.

When using translation keys as labels, you often end up with duplicated labels.
For instance, ``registration_first_name`` and ``profile_first_name``. To avoid
this, you can use the label format::

// ...
$formBuilder
->add('registration', new RegistrationType(), array(
'label_format' => 'form.person.%name%',
))
->add('profile', new ProfileType(), array(
'label_format' => 'form.person.%name%',
))
;

The option is inherited to the child types. With the code above, the
``first_name`` field of both forms will have the ``form.person.first_name``
label.
Copy link
Member Author

Choose a reason for hiding this comment

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

it found it a very difficult option to describe, I'm open for other suggestions!

3 changes: 3 additions & 0 deletions reference/forms/types/password.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The ``password`` field renders an input password text box.
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `max_length`_ (deprecated as of 2.5) |
| | - `read_only`_ |
Expand Down Expand Up @@ -68,6 +69,8 @@ The default value is ``''`` (the empty string).

.. 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/max_length.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/percent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This field adds a percentage sign "``%``" after the input box.
| | - `invalid_message_parameters`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -95,6 +96,8 @@ The default value is ``''`` (the empty string).

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/radio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ If you want to have a Boolean field, use :doc:`checkbox </reference/forms/types/
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `read_only`_ |
| | - `required`_ |
Expand Down Expand Up @@ -61,6 +62,8 @@ These options inherit from the :doc:`form </reference/forms/types/form>` type:

.. 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/read_only.rst.inc
Expand Down
3 changes: 3 additions & 0 deletions reference/forms/types/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Read about the input search field at `DiveIntoHTML5.info`_
| | - `error_mapping`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `label_format`_ |
| | - `mapped`_ |
| | - `max_length`_ (deprecated as of 2.5) |
| | - `read_only`_ |
Expand Down Expand Up @@ -52,6 +53,8 @@ The default value is ``''`` (the empty string).

.. 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/max_length.rst.inc
Expand Down
Loading