Skip to content

Commit 97c94d7

Browse files
committed
Updated getParent() description with the why/when (thanks javier!)
1 parent 68813a0 commit 97c94d7

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

form/create_custom_field_type.rst

Lines changed: 14 additions & 13 deletions
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

@@ -154,12 +151,16 @@ These are the most important methods that a form type class can define:
154151
recommended to use instead the ``buildView()`` method.
155152

156153
``getParent()``
157-
It returns a form type class name that is defined as the parent. All
158-
the other form type methods will be called with this parent type, and
159-
all its type extensions, before calling the ones defined in your custom
160-
type.
161-
By default, all classes extend the ``AbstractType`` class, which
162-
defines the ``FormType`` as the parent type.
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.
163164

164165
Defining the Form Type
165166
~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)