Multiple menu entires feature break local menu with non-standard menu use
daph2001 - September 13, 2009 - 06:47
| Project: | Local Menu |
| Version: | 6.x-1.6 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I use Drupal menus in slightly non-standard way, and the new multiple menu entries features breaks local menu in my site.
I have a bilingual site, with the content similar but not identical across the languages.
I don't use either primary or secondary links on my site (in build/menu/settings, source for both primary and secondary links is set to "no"). Instead I have a special per-language menu, and I have an explicit code in my theme that display the correct menu using the $language variable.
As my menus aren't standard, this loop (lines 72-82) never breaks, and $link isn't set at the end of the loop:
<?php
while ($link = menu_link_load(db_result($result))) {
if (in_array($link['menu_name'], array(
variable_get('menu_primary_links_source', 'primary-links'),
variable_get('menu_secondary_links_source', 'secondary-links'),
menu_get_active_menu_name(),
))) {
break;
}
}
?>I think the solution is that $link should by default contain the first value.

#1
All that code (and the while loop it's a part of) is saying is to check the primary-links, then secondary-links and then the current active menu to see if the node is in them and if it is, then break out of the WHILE loop with one of those 3 menus as the
menu_set_active_menu_name($link['menu_name']);
is called.
If the node isn't in one of those 3 menus that it'll be part of the last menu that the SQL result found. There's no ordering set for the SQL call, so it'll be the latest one that was entered.
I can't wait for weights :)
#2
Actually, there's all these references to the $link object after the while loop. Doesn't $link have to be set to global or something? I'm doing printouts and the $link is empty outside the while, but it's populated inside the while.
I'd say this module is broken if that's the case...?
I added these 3 lines to get it to work:
menu_set_active_menu_name($link['menu_name']); // this was outside the while - I brought it inside$depth = $link['depth']; // added#1
} // this closes the while loop
$link['menu_name'] = menu_get_active_menu_name(); // added#2
$link['depth'] = $depth; // added#3