Commit efc0e2e4 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2403301 by lokapujya, penyaskito, Wim Leers: Menu item "active" class...

Issue #2403301 by lokapujya, penyaskito, Wim Leers: Menu item "active" class is not correctly added when using a view as the frontpage
parent 2b9b727c
Loading
Loading
Loading
Loading
+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
@@ -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;
      }

+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
@@ -305,6 +305,25 @@ public function providerTestSetLinkActiveClass() {
      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;
  }