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

damien tournoud’s picture

Status: Needs review » Needs work

You need to update the cache key.

damien tournoud’s picture

Status: Needs work » Needs review

Actually not, I read that wrong, sorry.

chrisshattuck’s picture

This 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.

sun’s picture

Title: Pretty please, allow to pass custom 'conditions' to menu_build_tree(), kthxbye » Custom db_select 'conditions' parameter for menu_build_tree()
Category: task » feature

Better title. My silent hope was to be able to use this parameter starting with 7.1.

sun’s picture

Version: 7.x-dev » 8.x-dev
StatusFileSize
new1.16 KB

Re-rolled against latest branch HEAD.

sun’s picture

This 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.

chx’s picture

Status: Needs review » Reviewed & tested by the community

The 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.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

I 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.

sun’s picture

Status: Patch (to be ported) » Reviewed & tested by the community
StatusFileSize
new1.14 KB

Straight re-roll against D7 (/core dir only)

webchick’s picture

Title: Custom db_select 'conditions' parameter for menu_build_tree() » Change notice for: Custom db_select 'conditions' parameter for menu_build_tree()
Category: feature » task
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active

Seems reasonable to me!

Committed and pushed to 7.x. Thanks!

Per catch, this needs a change notice.

izus’s picture

Status: Active » Fixed

Added change notification http://drupal.org/node/1384082

Tor Arne Thune’s picture

Title: Change notice for: Custom db_select 'conditions' parameter for menu_build_tree() » Custom db_select 'conditions' parameter for menu_build_tree()
Category: task » feature
Priority: Critical » Normal

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

cweagans’s picture

Issue tags: +Needs backport to D7