EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Adding new event "BeforeEntityValidatedEvent" to dispatch before validation

Open astronati opened this issue 7 months ago • 0 comments

Adding new event to dispatch before validation A new event called BeforeEntityValidatedEvent extending AbstractLifecycleEvent can be used to manipulate when needed the entity before executing the validation but having the chance to access the entityInstance already created by the controller

Example of how to use this feature _ class BeforeEntityValidatedEvent extends AbstractLifecycleEvent {}

public function new(AdminContext $context)
{
        // ...
        $entityInstance = $newForm->getData();
        $context->getEntity()->setInstance($entityInstance);

		// New code ---
        $event = new BeforeEntityValidatedEvent($entityInstance);
        $this->container->get('event_dispatcher')->dispatch($event);
        $entityInstance = $event->getEntityInstance();
        // ----

        if ($newForm->isSubmitted() && $newForm->isValid()) {
            $this->processUploadedFiles($newForm);

_

astronati avatar Jul 19 '24 12:07 astronati