summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/locale/locale.module3
-rw-r--r--modules/simpletest/simpletest.module3
-rw-r--r--modules/system/system.module38
-rw-r--r--modules/system/system.test24
-rw-r--r--modules/user/user.module3
5 files changed, 63 insertions, 8 deletions
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 91038969f..6b1e3a62c 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 58c01b6f2..cad833381 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 1f9f2452d..c363e5aa7 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',
);
@@ -779,6 +783,25 @@ function _system_themes_access($theme) {
}
/**
+ * 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().
*/
function system_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 e49b26e5d..9756e9738 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 3a23cd772..fe16d994e 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',