/**
* Detects if there is a custom controller to use to render a Block.
*
* @param FilterControllerEvent $event
*
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
*/
public function getController(FilterControllerEvent $event)
{
$request = $event->getRequest();
// Only taking page related controller (i.e. ez_page:viewBlock or ez_page:viewBlockById)
if (strpos($request->attributes->get('_controller'), 'ez_page:') === false) {
return;
}
try {
if ($request->attributes->has('id')) {
$valueObject = $this->pageService->loadBlock($request->attributes->get('id'));
$request->attributes->set('block', $valueObject);
} elseif ($request->attributes->get('block') instanceof Block) {
$valueObject = $request->attributes->get('block');
$request->attributes->set('id', $valueObject->id);
}
} catch (UnauthorizedException $e) {
throw new AccessDeniedException();
}
if (!isset($valueObject)) {
$this->logger->error('Could not resolve a page controller, invalid value object to match.');
return;
}
$controllerReference = $this->controllerManager->getControllerReference($valueObject, 'block');
if (!$controllerReference instanceof ControllerReference) {
return;
}
$request->attributes->set('_controller', $controllerReference->controller);
$event->setController($this->controllerResolver->getController($request));
}