Skip to content

Commit 7ea53a3

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [Form] Added explicit `getParent()` call in types inheritance mechanism
2 parents d71a07e + c5b84ac commit 7ea53a3

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

form/create_custom_field_type.rst

+19-8
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ By convention they are stored in the ``src/Form/Type/`` directory::
5555
}
5656
}
5757

58-
The ``configureOptions()`` method, which is explained later in this article,
59-
defines the options that can be configured for the form type and sets the
60-
default value of those options.
61-
62-
The ``getParent()`` method defines which is the form type used as the base of
63-
this type. In this case, the type extends from ``ChoiceType`` to reuse all of
64-
the logic and rendering of that field type.
58+
The methods of the ``FormTypeInterface`` are explained in detail later in
59+
this article. Here, ``getParent()`` method defines the base type
60+
(``ChoiceType``) and ``configureOptions()`` overrides some of its options.
61+
The resulting form type is a choice field with predefined choices.
6562

6663
.. note::
6764

@@ -144,13 +141,27 @@ These are the most important methods that a form type class can define:
144141

145142
``configureOptions()``
146143
It defines the options configurable when using the form type, which are also
147-
the options that can be used in ``buildForm()`` and ``buildView()`` methods.
144+
the options that can be used in ``buildForm()`` and ``buildView()``
145+
methods. Options are inherited from parent types and parent type
146+
extensions, but you can create any custom option you need.
148147

149148
``finishView()``
150149
When creating a form type that consists of many fields, this method allows
151150
to modify the "view" of any of those fields. For any other use case, it's
152151
recommended to use instead the ``buildView()`` method.
153152

153+
``getParent()``
154+
If your custom type is based on another type (i.e. they share some
155+
functionality) add this method to return the fully-qualified class name
156+
of that original type. Do not use PHP inheritance for this.
157+
Symfony will call all the form type methods (``buildForm()``,
158+
``buildView()``, etc.) of the parent type and it will call all its type
159+
extensions before calling the ones defined in your custom type.
160+
161+
By default, the ``AbstractType`` class returns the generic
162+
:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType`
163+
type, which is the root parent for all form types in the Form component.
164+
154165
Defining the Form Type
155166
~~~~~~~~~~~~~~~~~~~~~~
156167

0 commit comments

Comments
 (0)