You are here

protected function CustomPageExceptionHtmlSubscriber::makeSubrequestToCustomPath in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\CustomPageExceptionHtmlSubscriber::makeSubrequestToCustomPath()

Makes a subrequest to retrieve the custom error page.

Parameters

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

string $custom_path: The custom path to which to make a subrequest for this error message.

int $status_code: The status code for the error being handled.

2 calls to CustomPageExceptionHtmlSubscriber::makeSubrequestToCustomPath()
CustomPageExceptionHtmlSubscriber::on403 in core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php
Handles a 403 error for HTML.
CustomPageExceptionHtmlSubscriber::on404 in core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php
Handles a 404 error for HTML.

File

core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php, line 95

Class

CustomPageExceptionHtmlSubscriber
Exception subscriber for handling core custom HTML error pages.

Namespace

Drupal\Core\EventSubscriber

Code

protected function makeSubrequestToCustomPath(GetResponseForExceptionEvent $event, $custom_path, $status_code) {
  $url = Url::fromUserInput($custom_path);
  if ($url
    ->isRouted()) {
    $access_result = $this->accessManager
      ->checkNamedRoute($url
      ->getRouteName(), $url
      ->getRouteParameters(), NULL, TRUE);
    $request = $event
      ->getRequest();

    // Merge the custom path's route's access result's cacheability metadata
    // with the existing one (from the master request), otherwise create it.
    if (!$request->attributes
      ->has(AccessAwareRouterInterface::ACCESS_RESULT)) {
      $request->attributes
        ->set(AccessAwareRouterInterface::ACCESS_RESULT, $access_result);
    }
    else {
      $existing_access_result = $request->attributes
        ->get(AccessAwareRouterInterface::ACCESS_RESULT);
      if ($existing_access_result instanceof RefinableCacheableDependencyInterface) {
        $existing_access_result
          ->addCacheableDependency($access_result);
      }
    }

    // Only perform the subrequest if the custom path is actually accessible.
    if (!$access_result
      ->isAllowed()) {
      return;
    }
  }
  $this
    ->makeSubrequest($event, $custom_path, $status_code);
}