EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

AssociationField creating new entries as tags

Open Michelium opened this issue 11 months ago • 0 comments

I have seen multiple questions about AssociationField but still haven't found the answer to this specific case.

Problem: I have an entity (LOBExercise) with the following field: #[ORM\ManyToMany(targetEntity: LOBTag::class, inversedBy: 'lOBExercises')] private Collection $lob_tag;

In the LOBExerciseCrudController I have the following field: image

I want to be able to create new Tags by adding them like this: image

However Symfony throws an error on this field because the new field is not in the database, which makes sense. I want to create the new entry in an event PRE_SUBMIT (and also thus pre validation)

I know in a Symfony form I can use this event to achieve this. However I can't get this to work in EasyAdmin image

I have tried multiple different ways, like creating a custom form type, using a collection field, using EventSubcribers and Doctrine events.

My question mainly is how to use FormEvents(::PRE_SUBMIT) for an EasyAdmin field. This is a farely standard use case I think. I would appreciate some insight in how to achieve this behaviour in EasyAdmin, thanks.

Michelium avatar Mar 08 '24 10:03 Michelium