Skip to content

[Form] Improve form type methods explanation #18585

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
Changes from all commits
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
41 changes: 22 additions & 19 deletions form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,6 @@ These are the most important methods that a form type class can define:

.. _form-type-methods-explanation:

``buildForm()``
It adds and configures other types into this type. It's the same method used
when :ref:`creating Symfony form classes <creating-forms-in-classes>`.

``buildView()``
It sets any extra variables you'll need when rendering the field in a template.

``finishView()``
This method allows to modify the "view" of any rendered widget. This is useful
if your form type consists of many fields, or contains a type that produces
many HTML elements (e.g. ``ChoiceType``). For any other use case, it's
recommended to use ``buildView()`` instead.

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

``getParent()``
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
Expand All @@ -149,6 +130,28 @@ These are the most important methods that a form type class can define:
:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType`
type, which is the root parent for all form types in the Form component.

``configureOptions()``
It defines the options configurable when using the form type, which are also
the options that can be used in the following methods. Options are inherited
from parent types and parent type extensions, but you can create any custom
option you need.

``buildForm()``
It configures the current form and may add nested fields. It's the same
method used when
:ref:`creating Symfony form classes <creating-forms-in-classes>`.

``buildView()``
It sets any extra variables you'll need when rendering the field in a form
theme template.

``finishView()``
Same as ``buildView()``. This is useful only if your form type consists of
many fields (i.e. A ``ChoiceType`` composed of many radio or checkboxes),
as this method will allow accessing child views with
``$view['child_name']``. For any other use case, it's recommended to use
``buildView()`` instead.

Defining the Form Type
~~~~~~~~~~~~~~~~~~~~~~

Expand Down