Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Form] Allow Form events to be used as expected withinherit_data
option#40515
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
PRE_SET_DATA
andPOST_SET_DATA
to be used withinherit_data
optionPRE_SET_DATA
andPOST_SET_DATA
to be used withinherit_data
optiond6aff48
toc833e0f
Compareb0c7af7
to46be0ae
ComparePRE_SET_DATA
andPOST_SET_DATA
to be used withinherit_data
optioninherit_data
optionadbecf2
to2ae62b6
Compareinherit_data
optioninherit_data
optionI am a bit worried that merging this would break existing applications that rely on the fact that their listeners are not called on forms that have the |
cristoforocervino commentedMar 26, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Should this behavior enabled with an option? |
Do you have a concrete use case in mind where removing this limitation would be useful? |
Using Let's suppose we have aform child we want to render as There is no way to achieve that without |
bbdd335
to3d1f8d4
Comparec0fdb09
toe1ccfe3
CompareAny chance of moving this forward? It seems extremely counter-intuitive that some FormEvents are called on child forms and others aren't. |
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.
Any event allowing to modify the data is actually incompatible with inherit_data by design. So I'm not sure we should pursue this.
if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA)) { | ||
$event = new PreSetDataEvent($form, $modelData); | ||
$dispatcher->dispatch($event, FormEvents::PRE_SET_DATA); | ||
$modelData = $event->getData(); |
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 would not allow child forms with inherit_data to change the model data of the parent form. This is a very bad idea IMO (and was one of the reasons why this was not supported)
} | ||
$event = new PreSubmitEvent($form, $eventSubmittedData); | ||
$dispatcher->dispatch($event, FormEvents::PRE_SUBMIT); | ||
$submittedData = $event->getData(); |
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 is broken. It will replace the whole submitted data by the data of the child only.
Why do you consider them incompatible? If this is by design it should be documented that some events trigger every time and others don't. |
@Amunak see my comments on those lines that describe the problems. |
@stof I understand. But if this is incompatible by design, wouldn't be better to throw an exception when you use |
Uh oh!
There was an error while loading.Please reload this page.
This PR allows
PRE_SET_DATA
,POST_SET_DATA
andSUBMIT
form events to be used also withinherit_data
option set totrue
.On top of that, usage of
PRE_SUBMIT
andPOST_SUBMIT
was allowed withinherit_data
optionbut dispatched events have$event->getData()
asnull
. This PR addresses that issue as well.Even if thedocumentation explains (at the very bottom of this page) that those form events are not going to work when the option
inherit_data
is used, I think it's a common problem you could run into with an advanced use of Form component (also becauseno exception is thrown when you use*_SET_DATA
,SUBMIT
andinherit_data
together).This is important to keep the high consistency standard Form component has.
Without this PR, the form component behaviour is ambiguous but known and documented, so I think we should consider this anew feature instead of a bug fix.