class AjaxResponseSubscriber in Views Ajax Get 8
Same name and namespace in other branches
- 2.0.x src/EventSubscriber/AjaxResponseSubscriber.php \Drupal\views_ajax_get\EventSubscriber\AjaxResponseSubscriber
Adding the headers for cache control so that these requests can be cached.
Hierarchy
- class \Drupal\views_ajax_get\EventSubscriber\AjaxResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of AjaxResponseSubscriber
1 string reference to 'AjaxResponseSubscriber'
1 service uses AjaxResponseSubscriber
File
- src/
EventSubscriber/ AjaxResponseSubscriber.php, line 14
Namespace
Drupal\views_ajax_get\EventSubscriberView source
class AjaxResponseSubscriber implements EventSubscriberInterface {
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
if (!$response instanceof ViewAjaxResponse) {
return;
}
$request = $event
->getRequest();
if (RouteMatch::createFromRequest($request)
->getRouteName() === 'views.ajax') {
/** @var \Drupal\views\ViewExecutable $view */
$view = $response
->getView();
// If view is excluded from conversion, don't add cache headers.
if (_views_ajax_get_is_ajax_get_view($view)) {
$view
->getRequest()->headers
->set('Cache-Control', 'public, max-age=' . \Drupal::config('system_performance_settings')
->get('cache.page.max_age'));
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = [
'onResponse',
0,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxResponseSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
AjaxResponseSubscriber:: |
public | function |