Spin-off from #519046: Clean up toolbar menu code and #296693: Restrict access to empty top level administration pages:

System module as well as Toolbar module as well as a couple of contrib modules require a menu system function to build a menu tree that starts from a given menu link and optionally ends at a specified level.

menu_tree_all_data() already takes an optional $max_depth parameter, but the $link parameter that can be passed in only allows to specify something along the lines of an active trail for the requested menu tree.

By introducing this, we can eliminate approx. 300 lines of totally awkward code from system.module, system.admin.inc, and toolbar.module - AND - most likely improve performance.

http://api.drupal.org/api/function/system_admin_menu_block_page/7
http://api.drupal.org/api/function/system_admin_config_page/7
http://api.drupal.org/api/function/system_admin_menu_block/7

Excerpt from Toolbar module:

+++ modules/toolbar/toolbar.module	6 Oct 2009 17:41:17 -0000
@@ -120,14 +120,12 @@ function toolbar_get_menu_tree() {
-    $tree = menu_tree_all_data('management', $admin_link);
+    // @todo Use a function like book_menu_subtree_data().
+    $tree = menu_tree_all_data('management', $admin_link, $admin_link['depth'] + 1);
     // The tree will be a sub-tree with the admin link as a single root item.
+    // @todo It is wrong to assume it's the last.
     $admin_link = array_pop($tree);
     $tree = $admin_link['below'] ? $admin_link['below'] : array();

So what we need here is a simple menu_subtree_data() function, which may even already exist, ready for rumble, in http://drupal.org/project/menu_block

Comments

sun’s picture

Adding #551080: List non-container items on /admin for a complete overview to the list of totally senseless workaround issues.

catch’s picture

Damien posted a patch along similar lines here, would probably make sense to merge #620618: Optimize menu tree building and use it for toolbar.

sun’s picture

Not 100% sure, but we can perhaps add contextual links to the list of possible consumers.

sun’s picture

Title: Toolbar + System module's "listing" pages (and blocks) require a menu_subtree_data() function » System module's "listing" pages (and blocks) should use menu_build_tree()
Status: Active » Postponed

Postponing on #620618: Optimize menu tree building and use it for toolbar, which seems to be ready to fly.

marcvangend’s picture

Doing some housekeeping in the issue queue... If this issue is critical, shouldn't #620618: Optimize menu tree building and use it for toolbar be marked as critical also?

sun’s picture

Priority: Critical » Normal

The previously mentioned issue may qualify as critical, but this one does not, I think.

marcvangend’s picture

Reverting title. Spam reported at http://drupal.org/node/856322.

catch’s picture

Status: Postponed » Active

Un-postponing this now that the other patch is in.

apaderno’s picture

marcvangend’s picture

Status: Active » Closed (outdated)

I don't think it's realistic to think that this will be fixed in D7, and it has already been improved in the D8 equivalent (SystemManager::getAdminBlock) which uses the menu tree manager service.