You are here

public function RouteAccessResponseSubscriber::onRespond in Drupal 8

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

Bubbles the route's access result' cacheability metadata.

Parameters

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

File

core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php, line 32

Class

RouteAccessResponseSubscriber
Response subscriber to bubble the route's access result's cacheability.

Namespace

Drupal\Core\EventSubscriber

Code

public function onRespond(FilterResponseEvent $event) {
  if (!$event
    ->isMasterRequest()) {
    return;
  }
  $response = $event
    ->getResponse();
  if (!$response instanceof CacheableResponseInterface) {
    return;
  }
  $request = $event
    ->getRequest();
  $access_result = $request->attributes
    ->get(AccessAwareRouterInterface::ACCESS_RESULT);
  $response
    ->addCacheableDependency($access_result);
}