class ConfigSubscriber in JSON:API Image Styles 2.0.x
Same name and namespace in other branches
- 3.0.x src/EventSubscriber/ConfigSubscriber.php \Drupal\jsonapi_image_styles\EventSubscriber\ConfigSubscriber
Associates config cache tag with all JSON:API responses.
Hierarchy
- class \Drupal\jsonapi_image_styles\EventSubscriber\ConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of ConfigSubscriber
1 string reference to 'ConfigSubscriber'
1 service uses ConfigSubscriber
File
- src/
EventSubscriber/ ConfigSubscriber.php, line 13
Namespace
Drupal\jsonapi_image_styles\EventSubscriberView source
class ConfigSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
// Run before
// \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber::onResponse()
// (priority 128) so config cache tag can be added.
$events[KernelEvents::RESPONSE][] = [
'onResponse',
129,
];
return $events;
}
/**
* Associates config cache tag with all JSON:API responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* Response event.
*/
public function onResponse(FilterResponseEvent $event) : void {
if ($event
->getRequest()
->getRequestFormat() !== 'api_json') {
return;
}
$response = $event
->getResponse();
if (!$response instanceof CacheableResponseInterface) {
return;
}
$response
->getCacheableMetadata()
->addCacheTags([
'config:jsonapi_image_styles.settings',
]);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigSubscriber:: |
public static | function | ||
ConfigSubscriber:: |
public | function | Associates config cache tag with all JSON:API responses. |