Commit 827e2784 authored by webchick's avatar webchick

#296693 by Damien Tournoud, boombatower, sun, and Xano: Hide parent...

#296693 by Damien Tournoud, boombatower, sun, and Xano: Hide parent administrative menu items when user has no access to any of their children.
parent e8364f51
......@@ -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',
......
......@@ -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',
......
......@@ -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;
}
......
......@@ -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 {
......
......@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment