Example #1
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     if ($exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
         return;
     }
     // If $notFoundPage is referencing a template, render it and be done.
     if ($this->render->hasTemplate($this->notFoundPage)) {
         try {
             $this->renderNotFound($event, $this->notFoundPage, []);
         } catch (TwigErrorLoader $e) {
             // Template not found, fall though to see if we can render a
             // record, failing that let the exception handler take over
         }
     }
     // Next try for referencing DB content.
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $this->renderNotFound($event, $template, $content->getTemplateContext());
 }
Example #2
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, $content->getTemplateContext());
     $event->setResponse($response);
 }
Example #3
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     // If $notFoundPage is referencing a template, render it and be done.
     if ($this->render->hasTemplate($this->notFoundPage)) {
         $response = $this->render->render($this->notFoundPage);
         $event->setResponse($response);
         return;
     }
     // Next try for referencing DB content.
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, [], $content->getTemplateContext());
     $event->setResponse($response);
 }