Spin-off from #519046: Clean up toolbar menu code and #296693: Hide empty admin categories:

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

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

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

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

Title:Toolbar + System module's "listing" pages (and blocks) require a menu_subtree_data() functionSystem 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.

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?

Priority:Critical» Normal

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

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

Status:Postponed» Active

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