Use an EntityType Form for Edit and New in EasyAdmin 3 and symfony 5

337 views Asked by At

I'm learning symfony 5 with EasyAdmin 3. I created a FormType for my entity, with label, attr, constraints (min, max). But to create or update my entity I use easyAdmin 3 and the constraints are not respected. I would like to create a Form (from my entity) and use it in crud/edit and crud/new template.

I override the template in my entityCrudController but I don't know how to integrate the entityForm inside.

thank you for your reply and sorry for my English :D

1

There are 1 answers

0
Cephalopodius On

you could use event. Something like

BeforeEntityPersistedEvent::class

With a checking

if ($entity instanceof $yourentity)

to make it trigger for the right entity and control if the data match the restriction, and

throw $this->createNotFoundException

if it doesnt. This way it will check each time before change the database.