/**
  * 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));
 }
 /**
  * Detects if there is a custom controller to use to render a Location/Content.
  *
  * @param FilterControllerEvent $event
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function getController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Only taking content related controller (i.e. ez_content:viewLocation or ez_content:viewContent)
     if (strpos($request->attributes->get('_controller'), 'ez_content:') === false) {
         return;
     }
     try {
         if ($request->attributes->has('locationId')) {
             $valueObject = $this->repository->getLocationService()->loadLocation($request->attributes->get('locationId'));
         } elseif ($request->attributes->get('location') instanceof Location) {
             $valueObject = $request->attributes->get('location');
             $request->attributes->set('locationId', $valueObject->id);
         } elseif ($request->attributes->has('contentId')) {
             $valueObject = $this->repository->sudo(function (Repository $repository) use($request) {
                 return $repository->getContentService()->loadContentInfo($request->attributes->get('contentId'));
             });
         } elseif ($request->attributes->get('contentInfo') instanceof ContentInfo) {
             $valueObject = $request->attributes->get('contentInfo');
             $request->attributes->set('contentId', $valueObject->id);
         }
     } catch (UnauthorizedException $e) {
         throw new AccessDeniedException();
     }
     if (!isset($valueObject)) {
         $this->logger->error('Could not resolver a view controller, invalid value object to match.');
         return;
     }
     $controllerReference = $this->controllerManager->getControllerReference($valueObject, $request->attributes->get('viewType'));
     if (!$controllerReference instanceof ControllerReference) {
         return;
     }
     $request->attributes->set('_controller', $controllerReference->controller);
     $event->setController($this->controllerResolver->getController($request));
 }