class RouteNameResponseSubscriber in Page Manager 8
Same name and namespace in other branches
- 8.4 src/EventSubscriber/RouteNameResponseSubscriber.php \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber
Adds the route name as a cache tag to all cacheable responses.
Hierarchy
- class \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RouteNameResponseSubscriber
1 file declares its use of RouteNameResponseSubscriber
1 string reference to 'RouteNameResponseSubscriber'
1 service uses RouteNameResponseSubscriber
File
- src/
EventSubscriber/ RouteNameResponseSubscriber.php, line 19 - Contains \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber.
Namespace
Drupal\page_manager\EventSubscriberView source
class RouteNameResponseSubscriber implements EventSubscriberInterface {
/**
* The master route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a new RouteNameResponseSubscriber.
*
* @param \Drupal\Core\Routing\StackedRouteMatchInterface $route_match
* The current route match.
*/
public function __construct(StackedRouteMatchInterface $route_match) {
$this->routeMatch = $route_match
->getMasterRouteMatch();
}
/**
* Adds the route name as a cache tag to all cacheable responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event to process.
*/
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,
]);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// Run before dynamic_page_cache_subscriber:onResponse.
$events[KernelEvents::RESPONSE][] = [
'onResponse',
101,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteNameResponseSubscriber:: |
protected | property | The master route match. | |
RouteNameResponseSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RouteNameResponseSubscriber:: |
public | function | Adds the route name as a cache tag to all cacheable responses. | |
RouteNameResponseSubscriber:: |
public | function | Constructs a new RouteNameResponseSubscriber. |