-
Bug
-
Resolution: Duplicate
-
Minor
-
None
-
4.4.4
-
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)
- Log to Moodle as an admin
- In the admin section, search for the custommenuitems setting (/admin/search.php?query=custommenuitems)
- Set the value of the custommenuitems setting to :
Item 1|https://www.moodle.com/ |
Item 2|/course/ |
Item 3|/course/search.php |
- Navigate to the Home page (/?redirect=0)
- 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!
- duplicates
-
MDL-83746 Custom menu item pointing to external site gets highlighted as active by mistake
-
- Closed
-