I have tried to get the menu tree for two different custom menus using menu_tree_all_data, but they have returned empty arrays, while using it to get 'navigation' menu works.
Does anyone have any idea about what might be going on?
If you are looking to print a menu tree, then it's answered here. I have tried this and solution worked !
<?php
$tree = menu_tree_page_data('menu-name'); // Replace menu-name with menu name you want to print
$first_level = db_query("SELECT mlid FROM {menu_links} where menu_name = 'menu-name' and plid = 0 ORDER BY weight ASC");
while ($item = db_fetch_object($first_level)) {
$mlid = $item->mlid;
// Extract subtree
$subtree = admin_console_menu_get_subtree($tree, $mlid);
// Render as HTML menu list
$content .= menu_tree_output($subtree);
}
return $content;
?>
/**
* Extract a specific subtree from a menu tree based on a menu link id (mlid)
*
* @param array $tree
* A menu tree data structure as returned by menu_tree_all_data() or menu_tree_page_data()
* @param int $mlid
* The menu link id of the menu entry for which to return the subtree
* @return array
* The found subtree, or NULL if no entry matched the mlid
*/
function admin_console_menu_get_subtree($tree, $mlid) {
// Check all top level entries
foreach ($tree as $key => $element) {
// Is this the entry we are looking for?
if ($mlid == $element['link']['mlid']) {
// Yes, return while keeping the key
return array($key => $element);
}
else {
// No, recurse to children, if any
if ($element['below']) {
$submatch = admin_console_menu_get_subtree($element['below'], $mlid);
// Found wanted entry within the children?
if ($submatch) {
// Yes, return it and stop looking any further
return $submatch;
}
}
}
}
// No match at all
return NULL;
}
Drupal adds 'menu-' to the menu name you specify, but doesn't use this on stock menus, so 'primary-links' works for the Primary Links menu.