Call embedded controller's createEntity() for CollectionField entries#7600
Open
lacatoire wants to merge 1 commit intoEasyCorp:5.xfrom
Open
Call embedded controller's createEntity() for CollectionField entries#7600lacatoire wants to merge 1 commit intoEasyCorp:5.xfrom
lacatoire wants to merge 1 commit intoEasyCorp:5.xfrom
Conversation
… entries When a CollectionField uses useEntryCrudForm() (or the field's CRUD controller is auto-discovered), Symfony Form was instantiating new entries through reflection on data_class, bypassing the embedded controller's createEntity() override. Default values, factory patterns, and other custom logic placed in createEntity() were silently dropped on new entries. Wire 'prototype_data' (read at build time, drives the prototype HTML) and 'entry_options.empty_data' (called by Symfony when binding a new empty entry on submit) to a closure that calls the embedded controller's createEntity(). Fixes EasyCorp#6991
b49cd56 to
aecbc19
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
CollectionFieldusesuseEntryCrudForm()(or the field's CRUD controller is auto-discovered through the entity's association), Symfony Form was instantiating new entries through reflection ondata_class, bypassing the embedded controller'screateEntity()override. Default values, factory patterns, and any other logic placed increateEntity()were silently dropped on the entries added through the parent form.This wires up the embedded controller's
createEntity()in two places inCollectionConfigurator::configureEntryType():prototype_data: read at build time, so the rendered prototype HTML reflects the defaults (e.g. checked checkboxes, pre-filled text inputs).entry_options.empty_data: called by Symfony Form for every new (empty) entry bound on submit, so the persisted entities also carry the defaults.Both default-
createEntity()(returnsnew $entityFqcn()) and overridden ones now flow through the same path, so there is no behavior change for users who don't override it.A regression test was added on top of
NestedCrudFormTest:ProjectIssueNestedCrudControllernow overridescreateEntity()with a marker name, and the test asserts that the marker shows up in the rendered prototype.Fixes #6991