diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 91038969f99620df88a2e70318af7b04b20e598e..6b1e3a62cb90ad37e164d607dd6813dab2350aab 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -76,7 +76,8 @@ function locale_menu() { 'position' => 'left', 'weight' => -7, 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_access', + 'access arguments' => array('admin/international', 'access administration pages'), ); $items['admin/international/language'] = array( 'title' => 'Languages', diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 58c01b6f2d1dcf5913e5e327419b668f7939ccb1..cad833381edd44f9da13bd8534678bf6779645f7 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -31,7 +31,8 @@ function simpletest_menu() { 'position' => 'right', 'weight' => -7, 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_access', + 'access arguments' => array('admin/development', 'access administration pages'), ); $items['admin/development/testing'] = array( 'title' => 'Testing', diff --git a/modules/system/system.module b/modules/system/system.module index 1f9f2452d4a1e4557ff419ce0be7e0059da2451c..c363e5aa7246eed4eda5d0d55eebf3d6949ccbbc 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -493,7 +493,8 @@ function system_menu() { 'position' => 'left', 'weight' => -10, 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_access', + 'access arguments' => array('admin/content', 'access administration pages'), ); // Menu items that are basically just menu blocks. @@ -503,7 +504,8 @@ function system_menu() { 'position' => 'right', 'weight' => -5, 'page callback' => 'system_settings_overview', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_access', + 'access arguments' => array('admin/settings', 'access administration pages'), ); $items['admin/build'] = array( 'title' => 'Site building', @@ -511,7 +513,8 @@ function system_menu() { 'position' => 'right', 'weight' => -10, 'page callback' => 'system_admin_menu_block_page', - 'access arguments' => array('access administration pages'), + 'access callback' => 'system_admin_menu_block_access', + 'access arguments' => array('admin/build', 'access administration pages'), ); // Themes. $items['admin/build/themes'] = array( @@ -726,7 +729,8 @@ function system_menu() { '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_access', + 'access arguments' => array('admin/reports', 'access site reports'), 'weight' => 5, 'position' => 'left', ); @@ -778,6 +782,25 @@ function _system_themes_access($theme) { return user_access('administer site configuration') && ($theme->status || $theme->name == variable_get('admin_theme', 0)); } +/** + * Menu item access callback - hides empty system settings overview pages. + * + * @param $path + * The path of the menu item to check for child menu entries. + * @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_access($path, $permission) { + if (!user_access($permission)) { + return FALSE; + } + $content = system_admin_menu_block(array('path' => $path)); + return !empty($content); +} + /** * Implementation of hook_init(). */ @@ -987,10 +1010,14 @@ function system_block_view($delta = '') { * The menu item to be displayed. */ function system_admin_menu_block($item) { - $content = array(); + $cache = &drupal_static(__FUNCTION__, array()); if (!isset($item['mlid'])) { $item += db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.router_path = :path AND module = 'system'", array(':path' => $item['path']))->fetchAssoc(); } + 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 @@ -1011,6 +1038,7 @@ function system_admin_menu_block($item) { $content[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $item; } ksort($content); + $cache[$item['mlid']] = $content; return $content; } diff --git a/modules/system/system.test b/modules/system/system.test index e49b26e5dbbf04b8cbbef863c35ccbb26b60c672..9756e97382718b75a781180969bb3dd1d6561076 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -370,6 +370,10 @@ class CronRunTestCase extends DrupalWebTestCase { } } + +/** + * Test administration pages and categories. + */ class AdminOverviewTestCase extends DrupalWebTestCase { /** * Implementation of getInfo(). @@ -435,6 +439,26 @@ class AdminOverviewTestCase extends DrupalWebTestCase { $this->assertFalse($extra, t('No extra panels found.')); } } + + /** + * Test administrative menu categories. + */ + public function testHideEmptyCategories() { + $user = $this->drupalCreateUser(array('administer nodes', 'access administration pages')); + $this->drupalLogin($user); + + $this->drupalGet('admin'); + + // Make sure menu items with children are displayed. + $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')); + } } class AdminMetaTagTestCase extends DrupalWebTestCase { diff --git a/modules/user/user.module b/modules/user/user.module index 3a23cd772feac611d2a38a492a6d5baa4b7ff509..fe16d994efda5bf034fe81700e5b0e128a6b73ba 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1335,7 +1335,8 @@ function user_menu() { '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_access', + 'access arguments' => array('admin/user', 'access administration pages'), ); $items['admin/user/user'] = array( 'title' => 'Users',