You are here

public function M4032404EventSubscriber::onAccessDeniedException in 403 to 404 8

Set the properly exception for event.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The response for exception event.

File

src/EventSubscriber/M4032404EventSubscriber.php, line 62

Class

M4032404EventSubscriber
Provides a subscriber to set the properly exception.

Namespace

Drupal\m4032404\EventSubscriber

Code

public function onAccessDeniedException(GetResponseForExceptionEvent $event) {
  if ($event
    ->getException() instanceof AccessDeniedHttpException) {
    $admin_only = $this->config
      ->get('admin_only');
    $is_admin = $this->adminContext
      ->isAdminRoute();
    if ((!$admin_only || $is_admin) && !$this->currentUser
      ->hasPermission('access 403 page')) {
      $event
        ->setException(new NotFoundHttpException());
    }
  }
}