8000 [Form] Added explicit `getParent()` call in types inheritance mechanism by wouterj · Pull Request #14588 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Form] Added explicit getParent() call in types inheritance mechanism #14588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Updated getParent() description with the why/when (thanks javier!)
  • Loading branch information
wouterj committed Nov 21, 2020
commit 97c94d77f4096b140da3ad303f7f3e9fa0ecdcb0
27 changes: 14 additions & 13 deletions form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ By convention they are stored in the ``src/Form/Type/`` directory::
}
}

The ``configureOptions()`` method, which is explained later in this article,
defines the options that can be configured for the form type and sets the
default value of those options.

The ``getParent()`` method defines which is the form type used as the base of
this type. In this case, the type extends from ``ChoiceType`` to reuse all of
the logic and rendering of that field type.
The methods of the ``FormTypeInterface`` are explained in detail later in
this article. Here, ``getParent()`` method defines the base type
(``ChoiceType``) and ``configureOptions()`` overrides some of its options.
The resulting form type is a choice field with predefined choices.

.. note::

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

``getParent()``
It returns a form type class name that is defined as the parent. All
the other form type methods will be called with this parent type, and
all its type extensions, before calling the ones defined in your custom
type.
By default, all classes extend the ``AbstractType`` class, which
defines the ``FormType`` as the parent type.
If your custom type is based on another type (i.e. they share some
functionality) add this method to return the fully-qualified class name
of that original type. Do not use PHP inheritance for this.
Symfony will call all the form type methods (``buildForm()``,
``buildView()``, etc.) of the parent type and it will call all its type
extensions before calling the ones defined in your custom type.

By default, the ``AbstractType`` class returns the generic
:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType`
type, which is the root parent for all form types in the Form component.

Defining the Form Type
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
0