public function ActiveLinkResponseFilter::onResponse in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter::onResponse()
Sets the 'is-active' class on links.
Parameters
\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The response event.
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ ActiveLinkResponseFilter.php, line 78
Class
- ActiveLinkResponseFilter
- Subscribes to filter HTML responses, to set the 'is-active' class on links.
Namespace
Drupal\Core\EventSubscriberCode
public function onResponse(FilterResponseEvent $event) {
$response = $event
->getResponse();
// Only care about HTML responses.
if (stripos($response->headers
->get('Content-Type'), 'text/html') === FALSE) {
return;
}
// For authenticated users, the 'is-active' class is set in JavaScript.
// @see system_page_attachments()
if ($this->currentUser
->isAuthenticated()) {
return;
}
// If content is FALSE, assume the response does not support the
// setContent() method and skip it, for example,
// \Symfony\Component\HttpFoundation\BinaryFileResponse.
$content = $response
->getContent();
if ($content !== FALSE) {
$response
->setContent(static::setLinkActiveClass($content, ltrim($this->currentPath
->getPath(), '/'), $this->pathMatcher
->isFrontPage(), $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_URL)
->getId(), $event
->getRequest()->query
->all()));
}
}