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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()
  ));
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.