Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[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

Open
cristoforocervino wants to merge3 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromcristoforocervino:pre-set-data-event-to-inherit-data-true-children

Conversation

cristoforocervino
Copy link
Contributor

@cristoforocervinocristoforocervino commentedMar 18, 2021
edited by OskarStark
Loading

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
Tickets#8607,#8834
LicenseMIT
Doc PRTODO

This PR allowsPRE_SET_DATA,POST_SET_DATA andSUBMIT form events to be used also withinherit_data option set totrue.
On top of that, usage ofPRE_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 optioninherit_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.

toooni, smnandre, and Amunak reacted with thumbs up emojizmitic reacted with heart emoji
@carsonbotcarsonbot changed the title[Form] AllowPRE_SET_DATA andPOST_SET_DATA to be used withinherit_data option[Form]  AllowPRE_SET_DATA andPOST_SET_DATA to be used withinherit_data optionMar 18, 2021
@cristoforocervinocristoforocervinoforce-pushed thepre-set-data-event-to-inherit-data-true-children branch 4 times, most recently fromd6aff48 toc833e0fCompareMarch 18, 2021 22:58
@xabbuhxabbuh added this to the5.x milestoneMar 19, 2021
@cristoforocervinocristoforocervinoforce-pushed thepre-set-data-event-to-inherit-data-true-children branch fromb0c7af7 to46be0aeCompareMarch 19, 2021 10:26
@cristoforocervinocristoforocervino changed the title[Form]  AllowPRE_SET_DATA andPOST_SET_DATA to be used withinherit_data option[Form]  Allow Form events to be used as expected withinherit_data optionMar 19, 2021
@cristoforocervinocristoforocervinoforce-pushed thepre-set-data-event-to-inherit-data-true-children branch 3 times, most recently fromadbecf2 to2ae62b6CompareMarch 19, 2021 10:40
@nicolas-grekasnicolas-grekas changed the title[Form]  Allow Form events to be used as expected withinherit_data option[Form] Allow Form events to be used as expected withinherit_data optionMar 19, 2021
@xabbuh
Copy link
Member

I 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 theinherit_data option enabled.

@cristoforocervino
Copy link
ContributorAuthor

cristoforocervino commentedMar 26, 2021
edited
Loading

Should this behavior enabled with an option?
I don't know, this is probably a BC Symfony 6.x could have but I see no reason to wait until then.
I'm open to suggestions to change this feature in order to make it safer for existing applications.

@xabbuh
Copy link
Member

Do you have a concrete use case in mind where removing this limitation would be useful?

@cristoforocervino
Copy link
ContributorAuthor

UsingPRE_SET_DATA event is the only way to add a form child and change its options based on given object state.

Let's suppose we have aform child we want to render asdisabledfalse when creating a new entity (letting the user to set its value) and render it asdisabletrue while editing (because the value cannot be changed but has to be shown).

There is no way to achieve that withoutPRE_SET_DATA on forms withinherit_data option.
The above is the actual use case that made me discover this Symfony Form limitation.

@cristoforocervinocristoforocervinoforce-pushed thepre-set-data-event-to-inherit-data-true-children branch 2 times, most recently frombbdd335 to3d1f8d4CompareApril 15, 2021 13:54
@fabpotfabpot removed this from the5.4 milestoneNov 16, 2021
@cristoforocervinocristoforocervinoforce-pushed thepre-set-data-event-to-inherit-data-true-children branch fromc0fdb09 toe1ccfe3CompareOctober 21, 2022 16:23
@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@Amunak
Copy link
Contributor

Any chance of moving this forward? It seems extremely counter-intuitive that some FormEvents are called on child forms and others aren't.

cristoforocervino reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
Copy link
Member

@stofstof left a 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();
Copy link
Member

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)

cristoforocervino reacted with thumbs up emoji
}
$event = new PreSubmitEvent($form, $eventSubmittedData);
$dispatcher->dispatch($event, FormEvents::PRE_SUBMIT);
$submittedData = $event->getData();
Copy link
Member

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.

@Amunak
Copy link
Contributor

Any event allowing to modify the data is actually incompatible with inherit_data by design. So I'm not sure we should pursue this.

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.

@stof
Copy link
Member

stof commentedDec 8, 2023

@Amunak see my comments on those lines that describe the problems.

@cristoforocervino
Copy link
ContributorAuthor

@stof I understand. But if this is incompatible by design, wouldn't be better to throw an exception when you use*_SET_DATA,SUBMIT andinherit_data together?

@symfonysymfony deleted a comment fromcarsonbotDec 9, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof requested changes

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

7 participants
@cristoforocervino@xabbuh@Amunak@stof@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp