diff --git a/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php b/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php index 8ccec8e..bddef30 100644 --- a/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php +++ b/core/modules/toolbar/lib/Drupal/toolbar/Tests/ToolbarAdminMenuTest.php @@ -100,6 +100,20 @@ function setUp() { } /** + * Tests that there is no Menu tab in the Toolbar for authenticated users. + * + * The authorized user should not have a Menu tab simply with the + * 'access toolbar' permission. + */ + function testEmptyMenuTray() { + // This is one test where we don't want an admin user. + $this->drupalLogout(); + $auth_user = $this->drupalCreateUser(array('access toolbar')); + $this->drupalLogin($auth_user); + $this->assertNoLinkByHref('/admin', 'The Admin Toolbar tab is not present.'); + } + + /** * Tests the toolbar_modules_installed() and toolbar_modules_uninstalled() hook * implementations. */ diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 096c489..c464ff8 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -355,56 +355,62 @@ function toolbar_toolbar() { // Retrieve the administration menu from the database. $tree = toolbar_get_menu_tree(); - // Add attributes to the links before rendering. - toolbar_menu_navigation_links($tree); - - $menu = array( - '#heading' => t('Administration menu'), - 'toolbar_administration' => array( - '#type' => 'container', - '#attributes' => array( - 'class' => array('toolbar-menu-administration'), + // If no menu links exist because the user does not have access to any, then + // don't render a menu tab. + if (!empty($tree)) { + + // Add attributes to the links before rendering. + toolbar_menu_navigation_links($tree); + + $menu = array( + '#heading' => t('Administration menu'), + 'toolbar_administration' => array( + '#type' => 'container', + '#attributes' => array( + 'class' => array('toolbar-menu-administration'), + ), + 'administration_menu' => menu_tree_output($tree), ), - 'administration_menu' => menu_tree_output($tree), - ), - ); + ); - // To conserve bandwidth, we only include the top-level links in the HTML. - // The subtrees are fetched through a JSONP script that is generated at the - // toolbar_subtrees route. We provide the JavaScript requesting that JSONP - // script here with the hash parameter that is needed for that route. - // @see toolbar_subtrees_jsonp() - $menu['toolbar_administration']['#attached']['js'][] = array( - 'type' => 'setting', - 'data' => array('toolbar' => array( - 'subtreesHash' => _toolbar_get_subtrees_hash(), - )), - ); + // To conserve bandwidth, we only include the top-level links in the HTML. + // The subtrees are fetched through a JSONP script that is generated at the + // toolbar_subtrees route. We provide the JavaScript requesting that JSONP + // script here with the hash parameter that is needed for that route. + // @see toolbar_subtrees_jsonp() + $menu['toolbar_administration']['#attached']['js'][] = array( + 'type' => 'setting', + 'data' => array('toolbar' => array( + 'subtreesHash' => _toolbar_get_subtrees_hash(), + )), + ); - // The administration element has a link that is themed to correspond to - // a toolbar tray. The tray contains the full administrative menu of the site. - $items['administration'] = array( - '#type' => 'toolbar_item', - 'tab' => array( - '#type' => 'link', - '#title' => t('Manage'), - '#href' => 'admin', - '#options' => array( - 'attributes' => array( - 'title' => t('Admin menu'), - 'class' => array('toolbar-icon', 'toolbar-icon-menu'), - // A data attribute that indicates to the client to defer loading of - // the admin menu subtrees until this tab is activated. Admin menu - // subtrees will not render to the DOM if this attribute is removed. - // The value of the attribute is intentionally left blank. Only the - // presence of the attribute is necessary. - 'data-drupal-subtrees' => '', + // The administration element has a link that is themed to correspond to + // a toolbar tray. The tray contains the full administrative menu of the + // site. + $items['administration'] = array( + '#type' => 'toolbar_item', + 'tab' => array( + '#type' => 'link', + '#title' => t('Manage'), + '#href' => 'admin', + '#options' => array( + 'attributes' => array( + 'title' => t('Admin menu'), + 'class' => array('toolbar-icon', 'toolbar-icon-menu'), + // A data attribute that indicates to the client to defer loading of + // the admin menu subtrees until this tab is activated. Admin menu + // subtrees will not render to the DOM if this attribute is removed. + // The value of the attribute is intentionally left blank. Only the + // presence of the attribute is necessary. + 'data-drupal-subtrees' => '', + ), ), ), - ), - 'tray' => $menu, - '#weight' => -15, - ); + 'tray' => $menu, + '#weight' => -15, + ); + } return $items; }