I'm trying to retrieve the menu link tree of "Add content" (including "Add content" itself) for Administration menu using menu_build_tree(), and the only thing that prevents me from using menu_build_tree() is that I can't pass custom query conditions.
Currently, I can only pass the following, but that retrieves the entire Navigation menu:
$node_add = db_query("SELECT * FROM {menu_links} WHERE router_path = 'node/add' AND module = 'system'")->fetch();
$tree = menu_build_tree($node_add->menu_name, array(
'expanded' => array($node_add->plid, $node_add->mlid),
'min_depth' => $node_add->depth,
));
What I want and need to do instead is:
$node_add = db_query("SELECT * FROM {menu_links} WHERE router_path = 'node/add' AND module = 'system'")->fetch();
$tree = menu_build_tree($node_add->menu_name, array(
'conditions' => array('p1' => $node_add->mlid),
'min_depth' => $node_add->depth,
));
Comments
Comment #1
damien tournoud commentedYou need to update the cache key.
Comment #2
damien tournoud commentedActually not, I read that wrong, sorry.
Comment #3
chrisshattuck commentedThis seems like a great idea. I guess I thought I must be missing something when I had to build the entire menu to grab a specific sub-set. So yeah, conditions would be nice.
Comment #4
sunBetter title. My silent hope was to be able to use this parameter starting with 7.1.
Comment #5
sunRe-rolled against latest branch HEAD.
Comment #6
sunThis would vastly help to get a stable of admin_menu out. I still refuse to copy/fork hundreds of menu.inc lines into the module to merely fetch a partial menu link tree.
Comment #7
chx commentedThe API purist in me yells "but you aren't supposed to know about pX columns and the like", the pragmatist in me yells "hey! admin_menu! awesome!". The pragmatist won. We are Drupal, we don't have nice APIs. Yet.
Comment #8
catchI think this is fine, it can't affect bc and it helps to unblock a stable release of a top ten module. Would be nice to see a follow-up for more flexible menu tree slices though and maybe looking at what from menu_block could be brought into core, but not sure what that follow-up should look like and we likely have it already somewhere.
Committed/pushed to 8.x.
This will need a change notice once it's been backported to 7.x.
Comment #9
sunStraight re-roll against D7 (/core dir only)
Comment #10
webchickSeems reasonable to me!
Committed and pushed to 7.x. Thanks!
Per catch, this needs a change notice.
Comment #11
izus commentedAdded change notification http://drupal.org/node/1384082
Comment #12
Tor Arne Thune commentedComment #14
cweagansUpdating tags per http://drupal.org/node/1517250