I have lots of menus on my site that have a similar link but different children. ActiveMenu currently has no way to support these (all menus with the same path share the same children).
I have managed to produce a workaround that fits my needs, but it requires modifications to the ActiveMenu code as well as a theme_menu_item hook to work properly. My solution modifies the menu item to put it's mid in the id attribute of the li tag. As far as I know there's no way to do this from within the module, and so I have to do it in my site's theme.
Once the mid is available on the page, the modified ActiveMenu requests the contents using this id (rather than the path). The amount of code change is minimal, but provides everything I need.
I would love to be able to make this a module only solution but I don't know how to modify the menu item's contents except through a theme.
I modified activemenu_js() like so:
function activemenu_js() {
if ($mid = activemenu_get_request_menu()) {
echo drupal_to_js(array('status' => TRUE, 'content' => theme('menu_tree', $mid)));
}
exit();
}
Added a function to ActiveMenu:
function activemenu_get_request_menu() {
return isset($_POST['mid']) ? intval($_POST['mid']) : FALSE;
}
And added the following function to my theme:
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'" id="'.$mid.'">'. menu_item_link($mid) . $children ."</li>\n";
}
Finally, I modified activemenu.js like so:
Line 34:
data: 'path=' + path,
becomes:
data: 'mid=' + this.id,
Comments
Comment #1
errolbert commentedMy earlier attempt broke the book menus. So, I modified it to restore the prior behavior in tandem.
Modify activemenu_js() like so:
Modify line 34 of activemenu.js like so: