public function TwitterWidgetSubscriber::onRespond in Twitter Profile Widget 8.2
Same name and namespace in other branches
- 8 src/EventSubscriber/TwitterWidgetSubscriber.php \Drupal\twitter_profile_widget\EventSubscriber\TwitterWidgetSubscriber::onRespond()
- 3.x src/EventSubscriber/TwitterWidgetSubscriber.php \Drupal\twitter_profile_widget\EventSubscriber\TwitterWidgetSubscriber::onRespond()
Sets extra headers on successful responses.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event to process.
File
- src/
EventSubscriber/ TwitterWidgetSubscriber.php, line 96
Class
- TwitterWidgetSubscriber
- Class TwitterWidgetSubscriber.
Namespace
Drupal\twitter_profile_widget\EventSubscriberCode
public function onRespond(FilterResponseEvent $event) {
$request = $event
->getRequest();
$response = $event
->getResponse();
$is_cacheable = $response instanceof CacheableResponseInterface && $this->requestPolicy
->check($request) === RequestPolicyInterface::ALLOW && $this->responsePolicy
->check($response, $request) !== ResponsePolicyInterface::DENY;
if ($is_cacheable) {
$response_cacheability = $response
->getCacheableMetadata();
$tags = $response_cacheability
->getCacheTags();
if (in_array('twitter_profile_widget', $tags)) {
$config = \Drupal::config('twitter_profile_widget.settings');
$expire = $config
->get('expire_internal_cache');
if ($expire) {
// Only act on pages that render the twitter_widget_view.
$this
->setExpiresCacheLifetime($response);
}
}
}
}