W3cubDocs

/Drupal 8

public function ActiveLinkResponseFilter::onResponse

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()
  ));
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!ActiveLinkResponseFilter.php/function/ActiveLinkResponseFilter::onResponse/8.1.x