Skip to content

Commit

Permalink
Documented label_format option
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Aug 21, 2015
1 parent ad4c1f0 commit 94c28d2
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/translation/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ recommended format. These files are parsed by one of the loader classes.
'symfony.great' => 'J\'aime Symfony',
);
.. _translation-real-vs-keyword-messages:

.. sidebar:: Using Real or Keyword Messages

This example illustrates the two different philosophies when creating
Expand Down
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
39 changes: 39 additions & 0 deletions reference/forms/types/options/label_format.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
label_format
~~~~~~~~~~~~

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

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

Configures the string used as label of the field. This is useful when using
:ref:`keyword translation messages <translation-real-vs-keyword-messages>`.

When using keyword translation messages as labels, you often end up having
several keyword messages translating to the same label (e.g.
``profile_address_street`` and ``invoice_address_street``). To avoid this,
you can use the label format::

// ...
$profileFormBuilder->add('address', new AddressType(), array(
'label_format' => 'form.address.%name%',
));

$invoiceFormBuilder->add('invoice', new AddressType(), array(
'label_format' => 'form.address.%name%',
));

The option is inherited to the child types. With the code above, the ``street``
field of both forms will use the ``form.address.street`` keyword message as the
label.

Two variables are available in the label format:

``%id%``
A unique identifier for the field, consisting of the complete path to the
field and the field name (e.g. ``profile_address_street``);
``%name%``
The field name (e.g. ``street``).

The default value (``null``) results in a
:ref:`"humanized" version <reference-twig-humanize-filter>` of the field name.
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

0 comments on commit 94c28d2

Please sign in to comment.