Skip to content

Commit 7112444

Browse files
committed
Merge branch '2.4'
2 parents 6c3d9eb + 4f64a29 commit 7112444

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

reference/forms/types/collection.rst

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ forms, which is useful when creating forms that expose one-to-many relationships
2626
| | - `error_mapping`_ |
2727
| | - `by_reference`_ |
2828
| | - `empty_data`_ |
29+
| | - `required`_ |
2930
| | - `mapped`_ |
3031
+-------------+-----------------------------------------------------------------------------+
3132
| Parent type | :doc:`form </reference/forms/types/form>` |
@@ -359,4 +360,6 @@ error_bubbling
359360

360361
.. include:: /reference/forms/types/options/empty_data.rst.inc
361362

363+
.. include:: /reference/forms/types/options/required.rst.inc
364+
362365
.. include:: /reference/forms/types/options/mapped.rst.inc

reference/forms/types/entity.rst

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ objects from the database.
1313
| Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) |
1414
+-------------+------------------------------------------------------------------+
1515
| Options | - `class`_ |
16+
| | - `data_class`_ |
1617
| | - `property`_ |
1718
| | - `group_by`_ |
1819
| | - `query_builder`_ |
@@ -105,6 +106,8 @@ The class of your entity (e.g. ``AcmeStoreBundle:Category``). This can be
105106
a fully-qualified class name (e.g. ``Acme\StoreBundle\Entity\Category``)
106107
or the short alias name (as shown prior).
107108

109+
.. include:: /reference/forms/types/options/data_class.rst.inc
110+
108111
property
109112
~~~~~~~~
110113

reference/forms/types/form.rst

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ on all fields.
1313

1414
.. include:: /reference/forms/types/options/data.rst.inc
1515

16+
.. include:: /reference/forms/types/options/data_class.rst.inc
17+
1618
.. include:: /reference/forms/types/options/required.rst.inc
1719

1820
.. include:: /reference/forms/types/options/label.rst.inc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. versionadded:: 2.4
2+
The ``data_class`` option was introduced in Symfony 2.4.
3+
4+
data_class
5+
~~~~~~~~~~
6+
7+
**type**: ``string``
8+
9+
This option is used to set the appropriate data mapper to be used by the form,
10+
so you can use it for any form field type which requires an object.
11+
12+
$builder->add('media', 'sonata_media_type', array(
13+
'data_class' => 'Acme\DemoBundle\Entity\Media',
14+
));

reference/forms/types/options/empty_data.rst.inc

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ choice is selected.
88

99
The true default value of this option depends on the field options:
1010

11-
* If ``compound`` is ``true`` and ``data_class`` is set, then ``new $data_class()``;
12-
* If ``compound`` is ``true`` and no ``data_class`` is set, then ``array()``;
13-
* If ``compound`` is ``false``, then ``null``.
11+
* If ``data_class`` is set and ``required`` is ``true``, then ``null``;
12+
* If ``data_class`` is set and ``required`` is ``false``, then ``new $data_class()``;
13+
* If ``data_class`` is not set and ``compound`` is ``true``, then ``array()``;
14+
* If ``data_class`` is not set and ``compound`` is ``false``, then ``null``.
1415

15-
.. tip::
16-
17-
The ``compound`` option is set to ``true`` when the field actually represents
18-
a collection of fields (e.g. a form of fields).
19-
20-
For example, if you want the ``gender`` field to be set to ``null`` when no
21-
value is selected, you can do it like this:
16+
But you can customize this to your needs. For example, if you want the ``gender`` field to be
17+
explicitly set to ``null`` when no value is selected, you can do it like this:
2218

2319
.. code-block:: php
2420

reference/forms/types/options/required.rst.inc

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ This is superficial and independent from validation. At best, if you let Symfony
1010
guess your field type, then the value of this option will be guessed from
1111
your validation information.
1212

13-
.. _`HTML5 required attribute`: http://diveintohtml5.info/forms.html
13+
.. note::
14+
15+
The required option does also affect the way how empty data of your form is
16+
being handled. For further details check the `empty_data`_ option.
17+
18+
.. _`HTML5 required attribute`: http://diveintohtml5.info/forms.html

0 commit comments

Comments
 (0)