Description
Currently, EasyAdmin provides hooks for events after an entity is persisted or updated. However, there is no clean way to intercept the lifecycle after a form is submitted but before $form->isValid() is called.
Adding a BeforeFormValidateEvent would allow developers to:
- Perform complex cross-field validation that isn't easily handled by standard Constraints.
- Stop the validation process and return a custom
Response (e.g., for AJAX/Vue integrations).
- Modify the entity or form data dynamically based on the raw submission before the validation engine runs.
Proposed Workflow
In AdminContext or the AbstractCrudController, the logic would look like this:
$form->handleRequest($request);
if ($form->isSubmitted()) {
$event = new BeforeFormValidateEvent($entityInstance, $form);
$this->container->get('event_dispatcher')->dispatch($event);
if ($event->isPropagationStopped()) {
return $event->getResponse();
}
if ($form->isValid()) {
// ... standard persistence logic
}
}
Potential Implementation
1. The Event Class:
A new BeforeFormValidateEvent class that holds the entityInstance, the form, and a setter for a response.
2. The Controller Integration:
Update EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController in the new() and edit() actions to dispatch this event immediately after handleRequest().
Why this is needed
In modern decoupled setups (like using Vue.js or Stimulus within EasyAdmin), we often need to validate credentials or external API states before Symfony attempts to map the request to the database. Without this event, we are forced to override the entire new() or edit() methods just to insert a few lines of validation logic.
Description
Currently, EasyAdmin provides hooks for events after an entity is persisted or updated. However, there is no clean way to intercept the lifecycle after a form is submitted but before
$form->isValid()is called.Adding a
BeforeFormValidateEventwould allow developers to:Response(e.g., for AJAX/Vue integrations).Proposed Workflow
In
AdminContextor theAbstractCrudController, the logic would look like this:Potential Implementation
1. The Event Class:
A new
BeforeFormValidateEventclass that holds theentityInstance, theform, and asetterfor a response.2. The Controller Integration:
Update
EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudControllerin thenew()andedit()actions to dispatch this event immediately afterhandleRequest().Why this is needed
In modern decoupled setups (like using Vue.js or Stimulus within EasyAdmin), we often need to validate credentials or external API states before Symfony attempts to map the request to the database. Without this event, we are forced to override the entire
new()oredit()methods just to insert a few lines of validation logic.