core/core.services.yml | 4 ++-- .../EventSubscriber/ActiveLinkResponseFilter.php | 28 +++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index be4398c..f0104bb 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1355,8 +1355,8 @@ services: email.validator: class: Egulias\EmailValidator\EmailValidator - active_link_response_filter: + response_filter.active_link: class: Drupal\Core\EventSubscriber\ActiveLinkResponseFilter - arguments: ['@current_user', '@current_route_match', '@path.matcher', '@language_manager'] + arguments: ['@current_user', '@path.current', '@path.matcher', '@language_manager'] tags: - { name: event_subscriber } diff --git a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php index 8f932da..b69d98a 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php +++ b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php @@ -10,6 +10,7 @@ use Drupal\Component\Serialization\Json; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; @@ -31,11 +32,11 @@ class ActiveLinkResponseFilter implements EventSubscriberInterface { protected $currentUser; /** - * The current route match. + * The current path. * - * @var \Drupal\Core\Routing\RouteMatchInterface + * @var \Drupal\Core\Path\CurrentPathStack */ - protected $routeMatch; + protected $currentPath; /** * The path matcher. @@ -52,14 +53,20 @@ class ActiveLinkResponseFilter implements EventSubscriberInterface { protected $languageManager; /** - * @param AccountInterface $current_user - * @param RouteMatchInterface $route_match - * @param PathMatcherInterface $path_matcher - * @param LanguageManagerInterface $language_manager + * Constructs a new ActiveLinkResponseFilter instance. + * + * @param \Drupal\Core\Session\AccountInterface $current_user + * The current user. + * @param \Drupal\Core\Path\CurrentPathStack $current_path + * The current path. + * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher + * The path matcher. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. */ - public function __construct(AccountInterface $current_user, RouteMatchInterface $route_match, PathMatcherInterface $path_matcher, LanguageManagerInterface $language_manager) { + public function __construct(AccountInterface $current_user, CurrentPathStack $current_path, PathMatcherInterface $path_matcher, LanguageManagerInterface $language_manager) { $this->currentUser = $current_user; - $this->routeMatch = $route_match; + $this->currentPath = $current_path; $this->pathMatcher = $path_matcher; $this->languageManager = $language_manager; } @@ -82,11 +89,10 @@ public function onResponse(FilterResponseEvent $event) { return; } - $current_path = $this->routeMatch->getRouteName() ? Url::fromRouteMatch($this->routeMatch)->getInternalPath() : ''; $response = $event->getResponse(); $response->setContent(static::setLinkActiveClass( $response->getContent(), - $current_path, + ltrim($this->currentPath->getPath(), '/'), $this->pathMatcher->isFrontPage(), $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(), $event->getRequest()->query->all()