Is it just me, or does it seem to others that top-level 'admin' items such as 'Content management' and 'Site building' should not appear in the menu at all when there are no child items?

I've accomplished this successfully by altering admin_menu_tree_output() to omit an item if 'plid' == 0 && 'link_path' begins with 'admin'. Also looked at _admin_menu_rebuild_links() but thought it might be more resource-intensive to pull the needed data for each item from {menu_links} in order to check for children.

CommentFileSizeAuthor
#6 admin_menu.categories.6.patch3.38 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ellen Dee’s picture

In case it isn't *just* me...

Here's a non-hacky way to hide these menu items, below. Issues may arise if admin_menu's external javascript doesn't load up before this is called-- my understanding is that $(document).ready() doesn't check external scripts-- but so far works fine for me.

** Note that hook_footer() is deprecated in Drupal 7. Not sure, but you might want to use hook_page_alter() as an alternative in D7.

Module code:

/**
 * Implementation of hook_footer().
 */
function mymodule_footer($main = 0) {
  if (user_access('access administration menu')) {
    return '<script type="text/javascript">
      $(document).ready(
        function() {
          $("#admin-menu > ul > li").each(
            function(index) {
              var found = $(this).find("ul");
              if ( found.length == 0 && !$(this).is(".admin-menu-action")) {
                 $(this).remove();
              }
            }
          );
        }
      ); 
      </script>';
  }
}

... or just insert near the bottom of page.tpl.php:

<?php if (user_access('access administration menu')): ?>
<script type="text/javascript">
$(document).ready(
  function() {
    $("#admin-menu > ul > li").each(
      function(index) {
        var found = $(this).find("ul");
        if ( found.length == 0 && !$(this).is(".admin-menu-action")) {
           $(this).remove();
        }
      }
    );
  }
);
</script>
<?php endif; ?>
sun’s picture

Status: Active » Closed (duplicate)

This is prominently covered on the project page, and caused by a Drupal core bug: #296693: Restrict access to empty top level administration pages

hanoii’s picture

Version: 6.x-1.5 » 7.x-3.x-dev
Status: Closed (duplicate) » Active

Just bringing this one to life a bit.

On D7, the normal administration screens do not show the empty items, but they do show on the admin_menu, is this a bug on D7 as well or is something that might be done on admin_menu?

hanoii’s picture

Ok, the high level admin categories do remain even as empty. But admin_menu is also showing sub items that should not be there really, as they not appear in the admin pages.

For instance, all of the configuration subitems are there, eventhough I only have access to one.

sun’s picture

Component: Code » User interface
Category: feature » task
Issue tags: +D7 stable release blocker
sun’s picture

Status: Active » Needs review
FileSize
3.38 KB

Passes for me.

sun’s picture

Title: Hide top-level 'admin' items when no children? » Hide links pointing to category/overview pages when empty
Status: Needs review » Fixed

Thanks for reporting, reviewing, and testing! Committed to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)
Issue tags: -D7 stable release blocker

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