Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84472

Wrong active link in primary navigation with custom menu items

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 4.4.4
    • Navigation
    • MOODLE_404_STABLE

      When custom menu items with absolute URL are added to the primary navigation, the wrong nav item is set to "active" when the user is on the home page.

      Steps to reproduce

      (Discovered on 4.4.4+, reproduced on 5.0dev)

      1. Log to Moodle as an admin
      2. In the admin section, search for the custommenuitems setting (/admin/search.php?query=custommenuitems)
      3. Set the value of the custommenuitems setting to :

      Item 1|https://www.moodle.com/
      Item 2|/course/
      Item 3|/course/search.php 

      # Save changes

      1. Navigate to the Home page (/?redirect=0)
      2. The "Item 1" nav link is marked as "active", when it is supposed to be the "Home" nav link that is active.

      The problem seems to occur in the /lib/classes/navigation/output/primary.php file, specifically in the merge_primary_and_custom() and flag_active_nodes() functions.

      When a custom node with an absolute URL without any path (ex. https://www.moodle.com/) is passed to the flag_active_nodes() function, the function algorithm determines it as equal to the current home page url, and sets $node->isactive to true. Then, in the merge_primary_and_custom() function, considering that a custom node is active, the Home nav element is then switched to "inactive" (lines 159-163).

      xdebug screenshot of the flag_active_nodes when processing the absolute URL :

      The host part of $current and $nodeurl should be compared together before comparing paths (line 211) :

       

      // Exact match of the host of node and current url.
      $nodehost = $nodeurl['host'] ?? '';
      $currenthost = $current['host'] ?? '';
      if ($nodehost !== $currenthost) {
          return false;
      } 

      Will try to commit the patch on my github in the coming days; i'm currently not setted up for it yet!

       

            Unassigned Unassigned
            yveshelie Yves Hélie
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.