Loading core/modules/system/src/Controller/SystemController.php +10 −4 Changes for core/modules/system/src/Controller/SystemController.php: 10 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -363,13 +363,19 @@ public static function setLinkActiveClass(array $element, array $context) { $pos_current_path = strpos($element['#markup'], $search_key_current_path, $offset); $pos_front = strpos($element['#markup'], $search_key_front, $offset); // Determine which of the two values matched: the exact path, or the // <front> special case. // Determine which of the two values is the next match: the exact path, or // the <front> special case. $pos_match = NULL; if ($pos_current_path !== FALSE) { if ($pos_front === FALSE) { $pos_match = $pos_current_path; } elseif ($context['front'] && $pos_front !== FALSE) { elseif ($pos_current_path === FALSE) { $pos_match = $pos_front; } elseif ($pos_current_path < $pos_front) { $pos_match = $pos_current_path; } else { $pos_match = $pos_front; } Loading core/modules/system/tests/src/Unit/Controller/SystemControllerTest.php +19 −0 Changes for core/modules/system/tests/src/Unit/Controller/SystemControllerTest.php: 19 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -305,6 +305,25 @@ public function providerTestSetLinkActiveClass() { 2 => ['#markup' => '<a data-drupal-link-system-path="<front>" class="active">Once</a> <a data-drupal-link-system-path="<front>" class="active">Twice</a>'], ]; // Test cases to verify that the 'active' class is added when on the front // page, and there are two different kinds of matching links on the page: // - the matching path (the resolved front page path) // - the special matching path ('<front>') $front_special_link = '<a data-drupal-link-system-path="<front>">Front</a>'; $front_special_link_active = '<a data-drupal-link-system-path="<front>" class="active">Front</a>'; $front_path_link = '<a data-drupal-link-system-path="myfrontpage">Front Path</a>'; $front_path_link_active = '<a data-drupal-link-system-path="myfrontpage" class="active">Front Path</a>'; $data[] = [ 0 => ['#markup' => $front_path_link . ' ' . $front_special_link], 1 => ['path' => 'myfrontpage', 'front' => TRUE, 'language' => 'en', 'query' => []], 2 => ['#markup' => $front_path_link_active . ' ' . $front_special_link_active], ]; $data[] = [ 0 => ['#markup' => $front_special_link . ' ' . $front_path_link], 1 => ['path' => 'myfrontpage', 'front' => TRUE, 'language' => 'en', 'query' => []], 2 => ['#markup' => $front_special_link_active . ' ' . $front_path_link_active], ]; return $data; } Loading Loading
core/modules/system/src/Controller/SystemController.php +10 −4 Changes for core/modules/system/src/Controller/SystemController.php: 10 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -363,13 +363,19 @@ public static function setLinkActiveClass(array $element, array $context) { $pos_current_path = strpos($element['#markup'], $search_key_current_path, $offset); $pos_front = strpos($element['#markup'], $search_key_front, $offset); // Determine which of the two values matched: the exact path, or the // <front> special case. // Determine which of the two values is the next match: the exact path, or // the <front> special case. $pos_match = NULL; if ($pos_current_path !== FALSE) { if ($pos_front === FALSE) { $pos_match = $pos_current_path; } elseif ($context['front'] && $pos_front !== FALSE) { elseif ($pos_current_path === FALSE) { $pos_match = $pos_front; } elseif ($pos_current_path < $pos_front) { $pos_match = $pos_current_path; } else { $pos_match = $pos_front; } Loading
core/modules/system/tests/src/Unit/Controller/SystemControllerTest.php +19 −0 Changes for core/modules/system/tests/src/Unit/Controller/SystemControllerTest.php: 19 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -305,6 +305,25 @@ public function providerTestSetLinkActiveClass() { 2 => ['#markup' => '<a data-drupal-link-system-path="<front>" class="active">Once</a> <a data-drupal-link-system-path="<front>" class="active">Twice</a>'], ]; // Test cases to verify that the 'active' class is added when on the front // page, and there are two different kinds of matching links on the page: // - the matching path (the resolved front page path) // - the special matching path ('<front>') $front_special_link = '<a data-drupal-link-system-path="<front>">Front</a>'; $front_special_link_active = '<a data-drupal-link-system-path="<front>" class="active">Front</a>'; $front_path_link = '<a data-drupal-link-system-path="myfrontpage">Front Path</a>'; $front_path_link_active = '<a data-drupal-link-system-path="myfrontpage" class="active">Front Path</a>'; $data[] = [ 0 => ['#markup' => $front_path_link . ' ' . $front_special_link], 1 => ['path' => 'myfrontpage', 'front' => TRUE, 'language' => 'en', 'query' => []], 2 => ['#markup' => $front_path_link_active . ' ' . $front_special_link_active], ]; $data[] = [ 0 => ['#markup' => $front_special_link . ' ' . $front_path_link], 1 => ['path' => 'myfrontpage', 'front' => TRUE, 'language' => 'en', 'query' => []], 2 => ['#markup' => $front_special_link_active . ' ' . $front_path_link_active], ]; return $data; } Loading