You are here

public function RouteNameResponseSubscriber::onResponse in Page Manager 8

Same name and namespace in other branches
  1. 8.4 src/EventSubscriber/RouteNameResponseSubscriber.php \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber::onResponse()

Adds the route name as a cache tag to all cacheable responses.

Parameters

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

File

src/EventSubscriber/RouteNameResponseSubscriber.php, line 44
Contains \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber.

Class

RouteNameResponseSubscriber
Adds the route name as a cache tag to all cacheable responses.

Namespace

Drupal\page_manager\EventSubscriber

Code

public function onResponse(FilterResponseEvent $event) {
  $response = $event
    ->getResponse();
  if ($response instanceof CacheableResponseInterface) {
    $cacheability_metadata = $response
      ->getCacheableMetadata();

    // If the route specifies a 'base route name', use that. Otherwise fall
    // back to the route name. The 'base route name' is specified in
    // \Drupal\page_manager\Routing\PageManagerRoutes.
    $route_name = $this->routeMatch
      ->getParameter('base_route_name') ?: $this->routeMatch
      ->getRouteName();
    $cacheability_metadata
      ->addCacheTags([
      'page_manager_route_name:' . $route_name,
    ]);
  }
}