@@ -16,8 +16,11 @@ Defining the Field Type
16
16
In order to create the custom field type, first you have to create the class
17
17
representing the field. In this situation the class holding the field type
18
18
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::
21
24
22
25
// src/AppBundle/Form/Type/ShippingType.php
23
26
namespace AppBundle\Form\Type;
@@ -54,8 +57,17 @@ for form fields, which is ``<BundleName>\Form\Type``. Make sure the field extend
54
57
Here, the return value of the ``getParent() `` function indicates that you're
55
58
extending the ``ChoiceType `` field. This means that, by default, you inherit
56
59
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:
59
71
60
72
.. _form-type-methods-explanation :
61
73
0 commit comments