EasyAdminBundle
EasyAdminBundle copied to clipboard
Adding new event "BeforeEntityValidatedEvent" to dispatch before validation
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);
_