Skip to content

Call embedded controller's createEntity() for CollectionField entries#7600

Open
lacatoire wants to merge 1 commit intoEasyCorp:5.xfrom
lacatoire:fix/createEntity-on-nested-crud-form-6991
Open

Call embedded controller's createEntity() for CollectionField entries#7600
lacatoire wants to merge 1 commit intoEasyCorp:5.xfrom
lacatoire:fix/createEntity-on-nested-crud-form-6991

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

When a CollectionField uses useEntryCrudForm() (or the field's CRUD controller is auto-discovered through the entity's association), Symfony Form was instantiating new entries through reflection on data_class, bypassing the embedded controller's createEntity() override. Default values, factory patterns, and any other logic placed in createEntity() were silently dropped on the entries added through the parent form.

This wires up the embedded controller's createEntity() in two places in CollectionConfigurator::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() (returns new $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: ProjectIssueNestedCrudController now overrides createEntity() with a marker name, and the test asserts that the marker shows up in the rendered prototype.

Fixes #6991

… 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
@lacatoire lacatoire force-pushed the fix/createEntity-on-nested-crud-form-6991 branch from b49cd56 to aecbc19 Compare May 7, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CrudControllerInterface::createEntity is not called when controller is embedded via useEntryCrudForm()

1 participant