I have spent the past week with my debugger deep in the bowels of the Drupal 5.x menu system trying to build a custom module for implementing what I call "Submenus." If I can ever get it to point of general purpose maturity I will definitely be contributing it as a module to the community.

However, I think I've run across a bug in menu.inc in an area that is probably not frequently exercised. What I'm trying to do is create dynamically generated nested menus using hook_menu() and I am then displaying the entire nested menu expanded in a block. This use case is to create custom task-specific menus for administration. The problem I'm running into is that I can't get the entire menu to be expanded all at once, only the "current trail" is expanded.

I looked at menu.inc and found that the menu_tree() function I am calling indirectly is looking in $_menu['visible'][<menu-id>]['type'] for menu type, and even when it is set to MENU_EXPANDED the menu items still do not expand.

Well the problem is $_menu['visible'][<menu-id>]['type'] is never set as far as I can tell. What gives be great confidence in my analysis is that the header comments for the function _menu_build_visible_tree() say "Since this is only for display, we only need title, path, and children for each item." Nowhere is there any mention of type though ironically that function does set the type!

The real problem is located is in the function _menu_append_contextual_items() which does NOT add an element for type in the menu item array even though the function menu_tree() makes heavy use of it:

  if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) { 
    foreach ($menu['visible'][$pid]['children'] as $mid) { 
      $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL; 
      $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL; 
      $output .= theme('menu_item', $mid, menu_in_active_trail($mid) || ($type & MENU_EXPANDED) ? theme('menu_tree', $mid) : '', count($children) == 0); 
    } 
  } 

Ahem. At least the header comments are consistent! : "We don't support the full range of menu item options for these menu items."

The fix for my use-case however appears to be trivially easy. All that is required is to change one line in _menu_append_contextual_items(), from this:

$_menu['visible'][$mid] = array('title' => $item['title'], 'path' => $item['path'], 'pid' => $pid);

To this:

$_menu['visible'][$mid] = array('title' => $item['title'], 'path' => $item['path'], 'pid' => $pid, 'type' => $item['type']);

Can we get this fix (and updated comments :) to be approved for 5.3?

Comments

jvandervort’s picture

Please add an issue in the queue for this one.

-John

-John

mikeschinkel’s picture

Thanks, but exactly how and where to I add an issue to the queue? I probably just need the URL...

jvandervort’s picture

http://drupal.org/project/issues

create link.

Project=drupal

Menu System or something like that.

-John

-John