Skip to content

Commit 526282e

Browse files
committed
[Form] Added explicit getParent() call in types inheritance mechanism
1 parent 15b9b9b commit 526282e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

form/create_custom_field_type.rst

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,30 @@ check out the `ChoiceType`_ class.
6767
extend from ``AbstractType`` is only a convenience way of implementing the
6868
required ``FormTypeInterface``.
6969

70-
There are three methods that are particularly important:
70+
There are four methods that are particularly important:
7171

7272
.. _form-type-methods-explanation:
7373

74+
``getParent()``
75+
This will defined the type configuring the form before. It means all the
76+
other other methods below will be called with this parent type and all its
77+
type extensions before calling the ones defined in your custom type.
78+
By default, all classes inherit the ``AbstractType`` which defines the
79+
``FormType`` as parent.
80+
81+
``configureOptions()``
82+
This defines options for your form type that
83+
can be used in ``buildForm()`` and ``buildView()``. There are a lot of
84+
options common to all fields (see :doc:`/reference/forms/types/form`),
85+
but you can create any others that you need here.
86+
7487
``buildForm()``
7588
Each field type has a ``buildForm()`` method, which is where
76-
you configure and build any field(s). Notice that this is the same method
77-
you use to setup *your* forms, and it works the same here.
89+
you configure and build any field(s) depending on options defined in
90+
``configureOptions()`` as well as those defined in parent types and
91+
their types extensions.
92+
Notice that this is the same method you use to setup *your* forms, and it
93+
works the same here.
7894

7995
``buildView()``
8096
This method is used to set any extra variables you'll
@@ -83,16 +99,11 @@ There are three methods that are particularly important:
8399
set) the ``multiple`` attribute on the ``select`` field. See
84100
`Creating a Template for the Field`_ for more details.
85101

86-
``configureOptions()``
87-
This defines options for your form type that
88-
can be used in ``buildForm()`` and ``buildView()``. There are a lot of
89-
options common to all fields (see :doc:`/reference/forms/types/form`),
90-
but you can create any others that you need here.
91-
92102
.. tip::
93103

94104
If you're creating a field that consists of many fields, then be sure
95-
to set your "parent" type as ``form`` or something that extends ``form``.
105+
to set your "parent" type as ``FormType::class`` or something that extends
106+
it.
96107
Also, if you need to modify the "view" of any of your child types from
97108
your parent type, use the ``finishView()`` method.
98109

0 commit comments

Comments
 (0)