Skip to content

Commit

Permalink
Fixed an important bug related to how controllers are executed
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed May 7, 2020
1 parent 0dda4ac commit 01e9dd7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/EventListener/AdminContextListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,17 @@ public function onKernelController(ControllerEvent $event): void
// this makes the AdminContext available in all templates as a short named variable
$this->twig->addGlobal('ea', $adminContext);

// if the request is related to a CRUD controller, change the controller to execute
if (null !== $crudControllerInstance) {
// Changes the controller associated to the current request to execute the
// CRUD controller and page requested via the dashboard menu and actions
$crudControllerClass = get_class($crudControllerInstance);
$crudControllerAction = $crudControllerCallable[1];
$newControllerAsString = sprintf('%s::%s', $crudControllerClass, $crudControllerAction);

// this makes Symfony believe that another controller is being executed
// (e.g. this is needed for the autowiring of controller action arguments)
$event->getRequest()->attributes->set('_controller', $newControllerAsString);

// this actually makes Symfony to execute the other controller
$event->setController($crudControllerCallable);
}
}
Expand Down

0 comments on commit 01e9dd7

Please sign in to comment.