Skip to content

Commit ab7cab3

Browse files
committed
Added a note about PHP extension and Symfony Form types extension
1 parent 70ff9a3 commit ab7cab3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

form/create_custom_field_type.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ Defining the Field Type
1616
In order to create the custom field type, first you have to create the class
1717
representing the field. In this situation the class holding the field type
1818
will be called ``ShippingType`` and the file will be stored in the default location
19-
for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extends
20-
:class:`Symfony\\Component\\Form\\AbstractType`::
19+
for form fields, which is ``<BundleName>\Form\Type``.
20+
21+
All field types must implement the :class:`Symfony\\Component\\Form\\FormTypeInterface`,
22+
but you should instead extend from :class:`Symfony\\Component\\Form\\AbstractType`,
23+
which already implements that interface and provides some utilities::
2124

2225
// src/AppBundle/Form/Type/ShippingType.php
2326
namespace AppBundle\Form\Type;
@@ -54,8 +57,17 @@ for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extend
5457
Here, the return value of the ``getParent()`` function indicates that you're
5558
extending the ``ChoiceType`` field. This means that, by default, you inherit
5659
all of the logic and rendering of that field type. To see some of the logic,
57-
check out the `ChoiceType`_ class. There are three methods that are particularly
58-
important:
60+
check out the `ChoiceType`_ class.
61+
62+
.. note::
63+
64+
The PHP class extension mechanism and the Symfony form field extension
65+
mechanism are not the same. The parent type returned in ``getParent()`` is
66+
what Symfony uses to build and manage the field type. Making the PHP class
67+
extend from ``AbstractType`` is only a convenience way of implementing the
68+
required ``FormTypeInterface``.
69+
70+
There are three methods that are particularly important:
5971

6072
.. _form-type-methods-explanation:
6173

0 commit comments

Comments
 (0)