Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 21f2d8f

Browse filesBrowse files
committed
minor #18585 [Form] Improve form type methods explanation (HeahDude)
This PR was merged into the 5.4 branch. Discussion ---------- [Form] Improve form type methods explanation I propose to keep methods ordered the same way they are used by the component: - `getParent()`: a type is first configured by its parent and its parent extensions - `configureOptions()`: a type defines what options are available - `buildForm()`: a type configures the current form and its fields based on defined options - `buildView()`: a type configures its view based on the built form and defined options - `finishView()`: a type configures its child views based on the built form, built view and defined options Commits ------- aeee305 [Form] Improve form type methods explanation
2 parents 57bf707 + aeee305 commit 21f2d8f
Copy full SHA for 21f2d8f

File tree

1 file changed

+22
-19
lines changed
Filter options

1 file changed

+22
-19
lines changed

‎form/create_custom_field_type.rst

Copy file name to clipboardExpand all lines: form/create_custom_field_type.rst
+22-19Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,6 @@ These are the most important methods that a form type class can define:
116116

117117
.. _form-type-methods-explanation:
118118

119-
``buildForm()``
120-
It adds and configures other types into this type. It's the same method used
121-
when :ref:`creating Symfony form classes <creating-forms-in-classes>`.
122-
123-
``buildView()``
124-
It sets any extra variables you'll need when rendering the field in a template.
125-
126-
``finishView()``
127-
This method allows to modify the "view" of any rendered widget. This is useful
128-
if your form type consists of many fields, or contains a type that produces
129-
many HTML elements (e.g. ``ChoiceType``). For any other use case, it's
130-
recommended to use ``buildView()`` instead.
131-
132-
``configureOptions()``
133-
It defines the options configurable when using the form type, which are also
134-
the options that can be used in ``buildForm()`` and ``buildView()``
135-
methods. Options are inherited from parent types and parent type
136-
extensions, but you can create any custom option you need.
137-
138119
``getParent()``
139120
If your custom type is based on another type (i.e. they share some
140121
functionality), add this method to return the fully-qualified class name
@@ -149,6 +130,28 @@ These are the most important methods that a form type class can define:
149130
:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType`
150131
type, which is the root parent for all form types in the Form component.
151132

133+
``configureOptions()``
134+
It defines the options configurable when using the form type, which are also
135+
the options that can be used in the following methods. Options are inherited
136+
from parent types and parent type extensions, but you can create any custom
137+
option you need.
138+
139+
``buildForm()``
140+
It configures the current form and may add nested fields. It's the same
141+
method used when
142+
:ref:`creating Symfony form classes <creating-forms-in-classes>`.
143+
144+
``buildView()``
145+
It sets any extra variables you'll need when rendering the field in a form
146+
theme template.
147+
148+
``finishView()``
149+
Same as ``buildView()``. This is useful only if your form type consists of
150+
many fields (i.e. A ``ChoiceType`` composed of many radio or checkboxes),
151+
as this method will allow accessing child views with
152+
``$view['child_name']``. For any other use case, it's recommended to use
153+
``buildView()`` instead.
154+
152155
Defining the Form Type
153156
~~~~~~~~~~~~~~~~~~~~~~
154157

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.