public function ActiveLinkResponseFilter::onResponse in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 83 - Contains \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter.
Class
- ActiveLinkResponseFilter
- Subscribes to filter HTML responses, to set the 'is-active' class on links.
Namespace
Drupal\Core\EventSubscriberCode
public function onResponse(FilterResponseEvent $event) {
// Only care about HTML responses.
if (stripos($event
->getResponse()->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;
}
$response = $event
->getResponse();
$response
->setContent(static::setLinkActiveClass($response
->getContent(), ltrim($this->currentPath
->getPath(), '/'), $this->pathMatcher
->isFrontPage(), $this->languageManager
->getCurrentLanguage(LanguageInterface::TYPE_URL)
->getId(), $event
->getRequest()->query
->all()));
}