-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] Added explicit getParent()
call in types inheritance mechanism
#13488
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,14 +67,31 @@ check out the `ChoiceType`_ class. | |
extend from ``AbstractType`` is only a convenience way of implementing the | ||
required ``FormTypeInterface``. | ||
|
||
There are three methods that are particularly important: | ||
There are a few methods that are particularly important: | ||
|
||
.. _form-type-methods-explanation: | ||
|
||
``getParent()`` | ||
This return the class name of the type configuring the form before. It | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not really sure if I completely understand what the meaning of the "the form before" part is supposed to be. |
||
means all the other methods below 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 inherit the ``AbstractType::getParent()`` which | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "[...] all classes extend the |
||
defines the ``FormType`` as parent type to re-use its options and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [...] as the parent type [...] |
||
configuration. | ||
|
||
``configureOptions()`` | ||
This defines options for your type that | ||
can be used in ``buildForm()`` and ``buildView()``. Options are inherited | ||
from parent types and parent types extension but you can create any custom | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [...] and parent type extensions, but [...] |
||
option you need. | ||
|
||
``buildForm()`` | ||
Each field type has a ``buildForm()`` method, which is where | ||
you configure and build any field(s). Notice that this is the same method | ||
you use to setup *your* forms, and it works the same here. | ||
you configure and build any field(s) depending on options defined in | ||
``configureOptions()``. | ||
Notice that this is the same method you use to set up *your* forms, and it | ||
works the same here. | ||
|
||
``buildView()`` | ||
This method is used to set any extra variables you'll | ||
|
@@ -83,18 +100,14 @@ There are three methods that are particularly important: | |
set) the ``multiple`` attribute on the ``select`` field. See | ||
`Creating a Template for the Field`_ for more details. | ||
|
||
``configureOptions()`` | ||
This defines options for your form type that | ||
can be used in ``buildForm()`` and ``buildView()``. There are a lot of | ||
options common to all fields (see :doc:`/reference/forms/types/form`), | ||
but you can create any others that you need here. | ||
``finishView`` | ||
Same as ``buildView`` but to configure the nested field views. | ||
This method as no use with types that build compound forms. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method has no use [...] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By the way, isn't that the other way around? |
||
|
||
.. tip:: | ||
|
||
If you're creating a field that consists of many fields, then be sure | ||
to set your "parent" type as ``form`` or something that extends ``form``. | ||
Also, if you need to modify the "view" of any of your child types from | ||
your parent type, use the ``finishView()`` method. | ||
If you're creating a field that consists of nested fields, then be sure to | ||
set the parent type as ``FormType::class`` or one of its child. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [...] or one of its children. |
||
|
||
The goal of this field was to extend the choice type to enable selection of the | ||
shipping type. This is achieved by fixing the ``choices`` to a list of available | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description focuses on "what/how" instead of "when/why". It explains that this is "like PHP inheritance but implemented in PHP, because you can't use real PHP inheritance".
But I'm missing information about the "why" and "when" to use this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a rewording.