diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 9ec9e3d..761e7ae 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -713,10 +713,10 @@ function shortcut_preprocess_page(&$variables) { } /** - * Implements hook_toolbar_register_tabs(). + * Implements hook_toolbar(). */ -function shortcut_toolbar_register_tabs() { - $tab['shortcuts'] = array( +function shortcut_toolbar() { + $items['shortcuts'] = array( 'tab' => array( 'title' => t('Shortcuts'), 'href' => '', @@ -730,7 +730,7 @@ function shortcut_toolbar_register_tabs() { ), ); - return $tab; + return $items; } /** diff --git a/core/modules/toolbar/toolbar.api.php b/core/modules/toolbar/toolbar.api.php new file mode 100644 index 0000000..783089b --- /dev/null +++ b/core/modules/toolbar/toolbar.api.php @@ -0,0 +1,97 @@ + array( + 'title' => t('Home'), + 'href' => '', + 'html' => FALSE, + 'attributes' => array( + 'title' => t('Home page'), + ), + ), + 'weight' => -10, + ); + + // Define the tray in a separate function. + $items['shortcuts'] = array( + 'tab' => array( + 'title' => t('Shortcuts'), + 'href' => '', + 'html' => FALSE, + 'attributes' => array( + 'title' => t('Shortcuts'), + ), + ), + 'tray' => array( + '#pre_render' => array('shortcut_toolbar_pre_render'), + ), + ); + + return $items; +} + +/** + * Alter the Toolbar menu after hook_toolbar() is invoked. + * + * This hook is invoked by toolbar_view() immediately after hook_toolbar(). The + * toolbar definitions are passed in by reference. Each element of the $items + * array is one item returned by a module from hook_toolbar(). Additional items + * may be added, or existing items altered. + * + * @param $items + * Associative array of Toolbar menu definitions returned from hook_toolbar(). + */ +function hook_toolbar_alter(&$items) { + // Move the User tab to the right. + $items['user']['weight'] = 5; +} + +/** + * @} End of "addtogroup hooks". + */ diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 0b6f1ae..e2dea63 100755 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -110,82 +110,95 @@ function toolbar_system_info_alter(&$info, $file, $type) { } /** - * Builds the admin menu as a structured array ready for drupal_render(). - * - * @return - * Array of links and settings relating to the admin menu. + * Implements hook_toolbar(). */ -function toolbar_view() { +function toolbar_toolbar() { + $items = array(); - $build = array( - '#theme' => 'toolbar', - '#attached'=> array( - 'library' => array( - array('toolbar', 'drupal.toolbar'), + // The 'Home' tab is a simple link, with no corresponding tray. + $items['home'] = array( + 'tab' => array( + 'title' => t('Home'), + 'href' => '', + 'html' => FALSE, + 'attributes' => array( + 'title' => t('Home page'), ), ), + 'weight' => -10, ); - // Get the configured breakpoint for switch from vertical to horizontal - // toolbar presentation. - $breakpoints = entity_load('breakpoint_group', 'module.toolbar.toolbar'); - if (!empty($breakpoints)) { - $build['#attached']['js'] = array( - array( - 'data' => array( - 'toolbar' => array( - 'breakpoints' => array(), - ), - ), - 'type' => 'setting', - ) - ); - // // Load the breakpoints for toolbar. - foreach ($breakpoints->breakpoints as $key => $breakpoint) { - $build['#attached']['js'][0]['data']['toolbar']['breakpoints'][$key] = $breakpoint->mediaQuery; - } - } - - // Build the default toolbar navigation links. // 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(); $menu['toolbar_administration'] = array( '#type' => 'container', '#attributes' => array( - 'class' => array('interactive-menu toolbar-list'), + 'class' => array('interactive-menu', 'toolbar-list'), ), + 'administration_menu' => menu_tree_output($tree), ); - $menu['toolbar_administration']['administration_menu'] = menu_tree_output($tree); - - $toolbar_groups = array( - 'home' => array( - 'tab' => array( - 'title' => t('Home'), - 'href' => '', - 'html' => FALSE, - ), - ), - 'administration' => array( - 'tab' => array( - 'title' => t('Menu'), - 'href' => '', - 'html' => FALSE, + + $items['administration'] = array( + 'tab' => array( + 'title' => t('Menu'), + 'href' => '', + 'html' => FALSE, + 'attributes' => array( + 'title' => t('Admin menu'), ), - 'tray' => $menu, ), + 'tray' => $menu, + 'weight' => -5, ); - // Get groups from other modules. - $toolbar_groups = array_merge($toolbar_groups, module_invoke_all('toolbar_register_tabs')); + return $items; +} - // Bar tabs. +/** + * Builds the admin menu as a structured array ready for drupal_render(). + * + * @return + * Array of links and settings relating to the admin menu. + */ +function toolbar_view() { + + $build = array('#theme' => 'toolbar'); + $build['#attached']['library'][] = array('toolbar', 'drupal.toolbar'); + + // Get the configured breakpoint for switch from vertical to horizontal + // toolbar presentation. + $breakpoints = entity_load('breakpoint_group', 'module.toolbar.toolbar'); + if (!empty($breakpoints)) { + $media_queries = array(); + $media_queries['toolbar']['breakpoints'] = array_map( + function($object) {return $object->mediaQuery;}, + $breakpoints->breakpoints); + + $build['#attached']['js'] = array(); + $build['#attached']['js'][] = array( + 'data' => $media_queries, + 'type' => 'setting', + ); + } + + // Get groups from all modules that implement hook_toolbar() or + // hook_toolbar_alter(). + $toolbar_groups = module_invoke_all('toolbar'); + drupal_alter('toolbar', $toolbar_groups); + uasort($toolbar_groups, 'drupal_sort_weight'); + + // Build the tabs and trays from the toolbar groups. $toolbar_tabs = array(); $toolbar_trays = array(); foreach ($toolbar_groups as $category => $components) { if (!empty($components['tab'])) { - // Provide a data attribute to each bar link that associates it with its tray. + // Provide a data attribute to each bar link that associates it with its + // tray. $components['tab']['attributes']['data-toolbar-tray'] = $category; if (!isset($components['tab']['attributes']['class'])) { $components['tab']['attributes']['class'] = array(); @@ -208,7 +221,8 @@ function toolbar_view() { ), '#heading' => array('text' => t('Drupal toolbar'), 'level' => 'h2', 'class' => 'element-invisible'), ); - //// Assign the tabs to the build. + + // Assign the trays to the build. $build['toolbar_trays'] = array( '#theme' => 'toolbar_tray', '#trays' => $toolbar_trays, diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 61e96cd..fa1a0a5 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -3070,23 +3070,26 @@ function user_file_download_access($field, EntityInterface $entity, File $file) } /** - * Implements hook_toolbar_register_tabs(). + * Implements hook_toolbar(). */ -function user_toolbar_register_tabs() { +function user_toolbar() { global $user; - $tab['user'] = array( + $items['user'] = array( 'tab' => array( 'title' => user_format_name($user), 'href' => '', 'html' => FALSE, + 'attributes' => array( + 'title' => t('My account'), + ), ), 'tray' => array( '#pre_render' => array('user_toolbar_pre_render'), ), ); - return $tab; + return $items; } /**