-
-
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
Conversation
1513ec3
to
526282e
Compare
526282e
to
4fc04cc
Compare
Thanks for the review, I've addressed everything. |
4fc04cc
to
e573c0a
Compare
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.
The only thing I'm not sure if I'm really missing is that you must have FormType
or any of its children as parent. I think it's sort of "unnecessary" information, but I also can see someone creating a type that has a completely weird parent (does the code catch this nicely, e.g. if I return stdClass
there?)
Basically, when creating child types, the intention should be one of the following:
The
Yes, |
I've edited my comment as I mixup up with type extensions. |
Th fourth option would be to implement the Maybe we should remove that sentence and add a clear note to explain all that. WDYT? |
|
||
.. _form-type-methods-explanation: | ||
|
||
``getParent()`` |
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:
- Is it mandatory to define this method?
- Which value should return this method? (the FQCN of a class implementing FormType??)
- How should I use this? (e.g. if you create a form type similar to an existing one, extend from it ... otherwise, extend from the generic FormType ??)
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.
cc8073c
to
a284b50
Compare
|
||
.. _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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
"[...] all classes extend the AbstractType
class [...]" or "[...] all classes inherit the AbstractType::getParent()
method [...]"?
and all its type extensions before calling the ones defined in your | ||
custom type. | ||
By default, all classes inherit the ``AbstractType::getParent()`` which | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
[...] as the parent type [...]
``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 comment
The reason will be displayed to describe this comment to others. Learn more.
[...] and parent type extensions, but [...]
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This method as no use with types that build compound forms.
By the way, isn't that the other way around?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
[...] or one of its children.
Hi @HeahDude. Do you have any time to finish on this PR? |
Closing in favor of #14588 |
…tance mechanism (HeahDude, wouterj) This PR was merged into the 4.4 branch. Discussion ---------- [Form] Added explicit `getParent()` call in types inheritance mechanism Continues #13488 Most of the original PR was already fixed in a slight rewrite of this article, but I think adding `getParent()` docs is still important. Commits ------- 97c94d7 Updated getParent() description with the why/when (thanks javier!) 68813a0 [Form] Added explicit `getParent()` call in types inheritance mechanism
No description provided.