Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.10 diff -u -r1.10 system.test --- modules/system/system.test 22 Aug 2008 12:35:55 -0000 1.10 +++ modules/system/system.test 24 Aug 2008 03:10:37 -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.613 diff -u -r1.613 system.module --- modules/system/system.module 21 Aug 2008 19:36:38 -0000 1.613 +++ modules/system/system.module 24 Aug 2008 03:15:11 -0000 @@ -367,7 +367,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 +378,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 +387,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 +621,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 +682,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 +802,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 +830,7 @@ $content[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $item; } ksort($content); + $cache[$item['mlid']] = $content; return $content; } @@ -1324,7 +1349,12 @@ */ function system_admin_compact_mode() { global $user; - return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE); + if ($user->uid) { + return (isset($user->admin_compact_mode)) ? $user->admin_compact_mode : variable_get('admin_compact_mode', FALSE); + } + else { + return (isset($_SESSION['admin_compact_mode'])) ? $_SESSION['admin_compact_mode'] : variable_get('admin_compact_mode', FALSE); + } } /** @@ -1335,7 +1365,12 @@ */ function system_admin_compact_page($mode = 'off') { global $user; - user_save($user, array('admin_compact_mode' => ($mode == 'on'))); + if ($user->uid) { + user_save($user, array('admin_compact_mode' => ($mode == 'on'))); + } + else { + $_SESSION['admin_compact_mode'] = ($mode == 'on'); + } drupal_goto(drupal_get_destination()); } Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.917 diff -u -r1.917 user.module --- modules/user/user.module 21 Aug 2008 19:36:39 -0000 1.917 +++ modules/user/user.module 24 Aug 2008 03:10:37 -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',