Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.9 diff -u -r1.9 system.test --- modules/system/system.test 23 Jul 2008 07:37:06 -0000 1.9 +++ modules/system/system.test 20 Aug 2008 23:44:30 -0000 @@ -320,3 +320,37 @@ $this->assertRaw($string, t('Fingerprinting meta tag generated correctly.'), t('System')); } } + +class AdminHideEmptyMenuCategoryTestCase extends DrupalWebTestCase { + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Hide empty menu categories'), + 'description' => t('Confirm that categories with no "visible" children using the system_admin_menu_block_page_access() + access callback are not displayed.'), + 'group' => t('System') + ); + } + + /** + * Ensure that menu items that without "visible" children are hidden. + */ + public function testEmptyHide() { + $user = $this->drupalCreateUser(array('administer nodes', 'access administration pages')); + $this->drupalLogin($user); + + $this->drupalGet('admin'); + + // Make sure menu items with children display. + $this->assertLink(t('Administer')); + $this->assertLink(t('Content management')); + + // Make sure menu items without children are hidden. + $this->assertNoLink(t('Site building')); + $this->assertNoLink(t('Site configuration')); + $this->assertNoLink(t('User management')); + $this->assertNoLink(t('Reports')); + } +} Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.612 diff -u -r1.612 system.module --- modules/system/system.module 2 Aug 2008 19:01:02 -0000 1.612 +++ modules/system/system.module 20 Aug 2008 23:44:30 -0000 @@ -338,26 +338,29 @@ ); $items['admin'] = array( 'title' => 'Administer', - 'access arguments' => array('access administration pages'), 'page callback' => 'system_main_admin_page', + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin', 'access administration pages'), 'weight' => 9, ); $items['admin/compact'] = array( 'title' => 'Compact mode', 'page callback' => 'system_admin_compact_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin', 'access administration pages'), 'type' => MENU_CALLBACK, ); $items['admin/by-task'] = array( 'title' => 'By task', 'page callback' => 'system_main_admin_page', - 'access arguments' => array('access administration pages'), + 'access arguments' => array('admin', 'access administration pages'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items['admin/by-module'] = array( 'title' => 'By module', 'page callback' => 'system_admin_by_module', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin', 'access administration pages'), 'type' => MENU_LOCAL_TASK, 'weight' => 2, ); @@ -367,7 +370,8 @@ 'position' => 'left', 'weight' => -10, 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin/content', 'access administration pages'), ); // menu items that are basically just menu blocks @@ -377,7 +381,8 @@ 'position' => 'right', 'weight' => -5, 'page callback' => 'system_settings_overview', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin/settings', 'access administration pages'), ); $items['admin/build'] = array( 'title' => 'Site building', @@ -385,7 +390,8 @@ 'position' => 'right', 'weight' => -10, 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin/build', 'access administration pages'), ); $items['admin/settings/admin'] = array( 'title' => 'Administration theme', @@ -618,7 +624,8 @@ 'title' => 'Reports', 'description' => 'View reports from system logs and other status information.', 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access site reports'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin/reports', 'access site reports'), 'weight' => 5, 'position' => 'left', ); @@ -678,6 +685,22 @@ } /** + * Menu item access callback - hides empty system settings overview pages. + * + * @param $path + * The path of the menu item to ensure has children. + * @param $string + * The permission, such as "administer nodes", being checked for. + * @return + * Boolean TRUE if the current user has the requested permission and the + * current menu item has children. + */ +function system_admin_menu_block_page_access($path, $permission) { + $content = system_admin_menu_block(array('path' => $path)); + return !empty($content) && user_access($permission); +} + +/** * Implementation of hook_init(). */ function system_init() { @@ -782,10 +805,14 @@ * The menu item to be displayed. */ function system_admin_menu_block($item) { - $content = array(); + static $cache; if (!isset($item['mlid'])) { $item += db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = '%s' AND module = 'system'", $item['path'])); } + else if (isset($cache[$item['mlid']])) { + return $cache[$item['mlid']]; + } + $content = array(); $result = db_query(" SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.* FROM {menu_links} ml @@ -806,6 +833,7 @@ $content[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $item; } ksort($content); + $cache[$item['mlid']] = $content; return $content; } Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.916 diff -u -r1.916 user.module --- modules/user/user.module 17 Aug 2008 10:46:30 -0000 1.916 +++ modules/user/user.module 20 Aug 2008 23:44:31 -0000 @@ -968,7 +968,8 @@ 'description' => "Manage your site's users, groups and access to site features.", 'position' => 'left', 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_page_access', + 'access arguments' => array('admin/user', 'access administration pages'), ); $items['admin/user/user'] = array( 'title' => 'Users',