Reading the documentation for menu_tree_page_data(), it seems to me that I should be able to retrieve the entire contents of my main menu by calling the function in the following way: menu_tree_page_data('main-menu'). Since param 2, $max_depth, defaults to NULL, this should recursively go through all levels. Since param 3, $only_active_trail, defaults to FALSE, this should retrieve all links, not just those on the active trail.
However, when calling this function, I end up with the following type of tree data.
All links on the first level of depth.
All links on the second level of depth.
Only active links on the third level of depth.
What’s going on here? I’ve also tried explicitly setting params as menu_tree_page_data('main-menu', 10, FALSE) just to make sure that I was not misinterpreting the default behavior. I’ve had to write my own function to give me the entire menu, but it doesn’t have active-trail data. Now, I’m finding myself in a situation where I’m blending the two functions to create a full menu tree WITH active-trail information, and it is extremely messy. It’d be great if one solution just worked.
Alternatively, is there a simple way of determining active trail for a given menu item? If so, I’ll just add that to my already-working tree-crawler function and call it a day.
I think it’s a problem with the static caching in
menu_tree_page_data(). The cache ID is built up using (among other things) the$max_depthpassed into the function orMENU_MAX_DEPTH, whichever is smaller.Since
MENU_MAX_DEPTHis equal to 9, when you pass 10 into the function this is automatically reset to 9, and the cache ID is built from that. If another function has already calledmenu_tree_page_data()withMENU_MAX_DEPTHas the$max_depthargument (which does happen earlier on in a Drupal page), and with$only_active_trailset toTRUEthen the statically cached data will be returned with only active trail items.I think the following will work:
If it doesn’t, you might also need to clear the cache for another function that’s involved (
_menu_build_tree()) so try this:Hope that makes sense it’s quite tricky to explain 🙂