public ActiveLinkResponseFilter::onResponse(FilterResponseEvent $event)
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\EventSubscriber
Code
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()
));
}
Please login to continue.