core/modules/system/src/Controller/SystemController.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 1df496a..cce4706 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -359,9 +359,7 @@ public static function setLinkActiveClass(array $element, array $context) { // An active link's path is equal to the current path, so search the HTML // for an attribute with that value. $offset = 0; - $matched_path = FALSE; - $matched_front = FALSE; - while ((!$matched_path && strpos($element['#markup'], 'data-drupal-link-system-path="' . $context['path'] . '"', $offset) !== FALSE || ($context['front'] && !$matched_front && strpos($element['#markup'], 'data-drupal-link-system-path="<front>"', $offset) !== FALSE))) { + while (strpos($element['#markup'], $search_key_current_path, $offset) !== FALSE || ($context['front'] && strpos($element['#markup'], $search_key_front, $offset) !== FALSE)) { $pos_current_path = strpos($element['#markup'], $search_key_current_path, $offset); $pos_front = strpos($element['#markup'], $search_key_front, $offset); @@ -370,11 +368,9 @@ public static function setLinkActiveClass(array $element, array $context) { $pos_match = NULL; if ($pos_current_path !== FALSE) { $pos_match = $pos_current_path; - $matched_path = TRUE; } elseif ($context['front'] && $pos_front !== FALSE) { $pos_match = $pos_front; - $matched_front = TRUE; } // Find beginning and ending of opening tag. @@ -401,9 +397,11 @@ public static function setLinkActiveClass(array $element, array $context) { @$dom->loadHTML('' . $tag . ''); $node = $dom->getElementsByTagName('body')->item(0)->firstChild; + // Ensure we don't set the "active" class twice on the same element. + $is_active = !in_array('active', explode(' ', $node->getAttribute('class'))); + // The language of an active link is equal to the current language. - $is_active = TRUE; - if ($context['language']) { + if ($is_active && $context['language']) { if ($node->hasAttribute('hreflang') && $node->getAttribute('hreflang') !== $context['language']) { $is_active = FALSE; }