When trying to output a highly customized menu tree, the existing menu_tree() is not very theme-friendly. The convention always employed is to override calls to menu_tree() to a custom one and its children. Just notice that admin_menu is doing the same.

e.g.

<?php
function _my_menu_tree($menu_name = 'navigation') {
...
  $menu_output[$menu_name] = _my_menu_tree_output($tree);
...
}

function _my_menu_tree_output($tree) {
...
  $link = _my_top_menu_item_link($data['link']);  // theme for 1st level menu
...
  $output .=  theme('menu_item', ..., _my_submenu_tree_output($data['below']), ...);
...
}

function _my_submenu_tree_output($tree) {
...
  $link = _my_sub_menu_item_link($data['link']);  // theme for sublevel menu
...
  $output .=  theme('menu_item', ..., _my_submenu_tree_output($data['below']), ...);
...
}
?>

which in turn need to duplicate the menu_tree_output() and often menu_item_link() as a custom function.

Another shortcoming is they are lacking the knowledge of the menu hierarchy (currently only come across menu_item_link may need that info). Often during themeing, we'll theme main menu differently especially a simple drop down menu, not to mention other more complex menu display (showing menu with inline description, themeing individual submenu differently, multiple columns etc).

It gets complicated during version upgrade as those codes need to be recoded if there are changes and could pose a security leak. A more theme-friendly menu_tree is needed in order to make drupal looks nicer. =)

Comments

ckng’s picture

I'm aware of theme_menu_tree(), often it is not relevant in customized menu as the tree html is already generated.

wretched sinner - saved by grace’s picture

sub. Want to help test this as I have found this oalso. My use was in creating a Sons of Suckerfish dropdown, and trying to have both and ID attached to the <ul> and printing the whole tree.

Was able to do one or other, but not both at the same time.

Freso’s picture

I'm currently bashing my head against this as well, as I want to theme a client's menu cleanly - but it's just not possible without making a custom menu_tree() (and customise other menu_*() functions as well).

Freso’s picture

I'm thinking that perhaps this is really a duplicate of #283723: Make menu_tree_output() return renderable output?

ckng’s picture

Status: Active » Closed (duplicate)

Fresco, you are right, marking this as duplicate.
Head over to #283723: Make menu_tree_output() return renderable output