By brooklynwebguy on
I would like more control of the menus. I would like to be able to get a menu as an array containing the related node information. I realize I can use theme_menu_tree and then use a regexp to break it up, but that doesn't seem particular efficient to have the system first format the data and then unformat it.
Is there a function like theme_menu_tree that just sends back the node info for each of the links?
Comments
how about
http://api.drupal.org/api/5/function/menu_get_menu
Menu items store paths not nodes though. If you need node info from a menu item, you'd need to use the path to look it up.
--
Anton
New to Drupal? | Troubleshooting FAQ
Example knowledge base built with Drupal
Must have been done before?
I would also like to have as an array the same menu structure that is displayed in e.g. menu blocks. It would only need to provide the $mid of each menu item, functions like menu_get_item could then be used to fetch more info or do whatever you like to each item.
Something like this must have been done before, I just can't seem to find it...
If anybody knows of a module doing this, or has a function, please feel free to share :)
You might find this helpful
I ended up just parsing through the theme_menu_tree string using SimpleXML. Seems silly to get markup when all you want is data but the theme_menu_tree markup contains some useful info (titles, link states, submenu) that's pretty easy to get at with rudimentary xpath.
Here is a node where this is discussed.
http://drupal.org/node/138236#comment-225013
Have no idea how this solution scales but I doubt if it's too problematic. In your case you could use SimpleXML (or reg. exp) to tease out the paths, throw them into a where clause and then do one database query on url_alias to get the mids.
If you find a better way, let us all know.