Issue #2403301 by lokapujya, penyaskito, Wim Leers: Menu item "active" class is not correctly added when using a view as the frontpage

8.0.x
Alex Pott 2015-02-14 16:41:03 +00:00
parent 2b9b727c29
commit efc0e2e41d
2 changed files with 29 additions and 4 deletions

View File

@ -363,13 +363,19 @@ class SystemController extends ControllerBase {
$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;
}

View File

@ -305,6 +305,25 @@ class SystemControllerTest extends UnitTestCase {
2 => ['#markup' => '<a data-drupal-link-system-path="&lt;front&gt;" class="active">Once</a> <a data-drupal-link-system-path="&lt;front&gt;" 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="&lt;front&gt;">Front</a>';
$front_special_link_active = '<a data-drupal-link-system-path="&lt;front&gt;" 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;
}