You are here

public function NotFound::on403 in Unpublished 404 8

Handles all 4xx errors for all serialization failures.

Parameters

\Symfony\Component\HttpKernel\Event\ExceptionEvent $event: The event to process.

File

src/EventSubscriber/NotFound.php, line 52

Class

NotFound
Redirects 403 node page error responses to 404 page.

Namespace

Drupal\unpublished_404\EventSubscriber

Code

public function on403(ExceptionEvent $event) {

  // Check if current user has pemission to view own unpublished content.
  if ($this->account && !$this->account
    ->hasPermission('view own unpublished content')) {
    $request = $event
      ->getRequest();
    if ($node = $request->attributes
      ->get('node')) {
      if (!$node
        ->isPublished()) {
        $event
          ->setThrowable(new NotFoundHttpException());
      }
    }
  }
}