function RouteAccessResponseSubscriber::onRespond

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php \Drupal\Core\EventSubscriber\RouteAccessResponseSubscriber::onRespond()
  2. 10 core/lib/Drupal/Core/EventSubscriber/RouteAccessResponseSubscriber.php \Drupal\Core\EventSubscriber\RouteAccessResponseSubscriber::onRespond()
  3. 11.x 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\ResponseEvent $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(ResponseEvent $event) {
    if (!$event->isMainRequest()) {
        return;
    }
    $response = $event->getResponse();
    if (!$response instanceof CacheableResponseInterface) {
        return;
    }
    $request = $event->getRequest();
    $access_result = $request->attributes
        ->get(AccessAwareRouterInterface::ACCESS_RESULT);
    $response->addCacheableDependency($access_result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.