diff --git a/admin_menu.api.php b/admin_menu.api.php index 2d212fb..83d4068 100644 --- a/admin_menu.api.php +++ b/admin_menu.api.php @@ -162,3 +162,28 @@ function hook_admin_menu_cache_info() { ); return $caches; } + +/** + * Alter the default admin menu access policy. + * + * By default, the admin menu can be displayed when the current user is granted + * with the 'access administration menu' permission. But a module can override + * this behavior by implementing this hook. A hook implementation should return. + * The access to administrative menu is granted if: + * - No modules returns a strict FALSE. + * - At least one module returns a strict TRUE. + * If no module returned either TRUE or FALSE, the 'access administration menu' + * permission is checked. + * + * @return bool|null + * Boolean allowing or denying the access or NULL to let other modules to act. + */ +function hook_admin_menu_access() { + global $user; + if ($user->is_manager) { + // Managers are able to access the administrative menu. + return TRUE; + } + + // Don't return nothing. We let other modules to take the decision. +} diff --git a/admin_menu.module b/admin_menu.module index 21bff9f..fc34162 100644 --- a/admin_menu.module +++ b/admin_menu.module @@ -66,7 +66,7 @@ function admin_menu_menu() { $items['js/admin_menu/cache'] = array( 'page callback' => 'admin_menu_js_cache', 'delivery callback' => 'admin_menu_deliver', - 'access arguments' => array('access administration menu'), + 'access callback' => 'admin_menu_access_admin_menu', 'type' => MENU_CALLBACK, ); // Module settings. @@ -147,7 +147,7 @@ function admin_menu_system_info_alter(&$info, $file, $type) { * Implements hook_page_build(). */ function admin_menu_page_build(&$page) { - if (!user_access('access administration menu') || admin_menu_suppress(FALSE)) { + if (!admin_menu_access_admin_menu() || admin_menu_suppress(FALSE)) { return; } // Performance: Skip this entirely for AJAX requests. @@ -241,6 +241,27 @@ function admin_menu_page_build(&$page) { } /** + * Provides an access callback for accessing the administrative menu. + * + * @return bool + * TRUE if the access is permitted. + */ +function admin_menu_access_admin_menu() { + $access = module_invoke_all('admin_menu_access'); + if (in_array(FALSE, $access, TRUE)) { + // If at least one module denies, then deny. + return FALSE; + } + elseif (in_array(TRUE, $access, TRUE)) { + // If no one denies and at least one grants, the allow. + return TRUE; + } + + // Fall back to permission setting. + return user_access('access administration menu'); +} + +/** * Suppress display of administration menu. * * This function should be called from within another module's page callback