Issue with CollectionField in an Embedded Form
I’m having an issue with a CollectionField inside an embedded form using renderAsEmbeddedForm().
Context:
I have an entity Formation that is linked to an InscriptionProcess entity by a One-To-One relationship. Each InscriptionProcess contains multiple InscriptionStep entities.
In the Formation CRUD, I include the InscriptionProcess form directly with:
AssociationField::new('inscriptionProcess')
->setFormTypeOption('by_reference', false)
->renderAsEmbeddedForm(InscriptionProcessCrudController::class),
In InscriptionProcessCrudController, I have a CollectionField to manage the steps:
CollectionField::new('steps', 'Steps')
->setEntryIsComplex()
->allowDelete(true)
->allowAdd(true)
->useEntryCrudForm(InscriptionStepCrudController::class)
->setFormTypeOptions([
'by_reference' => false,
])
The InscriptionStep entity has some basic fields:
TextField::new('title', 'Title'),
TextField::new('text', 'Text'),
TextField::new('duration', 'Duration'),
Issue:
In the Formation edit form, I can add and modify steps, but the delete button is missing.
The steps are not displayed as a dropdown (as they normally should be with CollectionField and useEntryCrudForm()), but instead appear as a list with all fields visible at once.
What it currentyl looks like Something similar that is properly working / What it should look like
What I’ve Tried:
-Ensuring allowDelete(true) is enabled -Verifying that the InscriptionProcess entity has cascade: ['persist', 'remove'] and orphanRemoval: true -Testing thatCollectionField works correctly in other cases
It seems like renderAsEmbeddedForm() is breaking something in the CollectionField display, but I’d prefer to keep the registration process form inside the Formation form.
Has anyone encountered this issue before? Or any ideas on how to fix this ?
I have a similar issue where my embedded Crud Controller contains a CollectionField, but I am unable to create new entities within the given embedded field.
I.e. I cannot even create a new one.
This is my code:
yield FormField::addTab(t('Contact persons'), 'fal fa-users');
yield CollectionField::new('employees', t('Contact persons'))
->useEntryCrudForm(PersonCrudController::class)
->hideOnIndex()
->allowAdd()
->allowDelete()
->setEntryIsComplex(true)
->setFormTypeOptions([
'by_reference' => false,
])
->setColumns('col-sm-12');
I can see that the events on the Create New Button are not registered, so nothing happens when I click the link.
What helped me is to inject this line into my configureAssets method in my controller where I embed the secondary form (that holds the collection field).
public function configureAssets(Assets $assets): Assets
{
$assets = parent::configureAssets($assets);
$assets->addJsFile(Asset::fromEasyAdminAssetPackage('field-collection.js')->onlyOnForms());
return $assets;
}
This issue has been inactive for 3 months. It will be closed in 5 days unless there is new activity.
Check if this is still relevant (maybe it was already fixed by some PR) and leave a comment or update the issue with any new information.
Thanks for reporting this.
We are closing this issue because it has had no activity for the last 3 months. This helps us keep the tracker manageable and focus on actively discussed work.
If this is still relevant, please reopen the issue (or open a new one) with updated information, and any logs or stack traces you can share.