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
Comment #1
sunAdding #551080: List non-container items on /admin for a complete overview to the list of totally senseless workaround issues.
Comment #2
catchDamien posted a patch along similar lines here, would probably make sense to merge #620618: Optimize menu tree building and use it for toolbar.
Comment #3
sunNot 100% sure, but we can perhaps add contextual links to the list of possible consumers.
Comment #4
sunPostponing on #620618: Optimize menu tree building and use it for toolbar, which seems to be ready to fly.
Comment #5
marcvangendDoing 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?
Comment #6
sunThe previously mentioned issue may qualify as critical, but this one does not, I think.
Comment #9
marcvangendReverting title. Spam reported at http://drupal.org/node/856322.
Comment #10
catchUn-postponing this now that the other patch is in.
Comment #11
apadernoComment #12
marcvangendI 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.