' . t('The Toolbar module displays a bar containing top-level administrative links across the top of the screen. Below that, the Toolbar module has a drawer section where it displays links provided by other modules, such as the core Shortcut module. The drawer can be hidden/shown by using the show/hide shortcuts link at the end of the toolbar.', array('@shortcuts-help' => url('admin/help/shortcut'))) . '
';
+ $output .= '
' . t('The Toolbar module displays a bar containing top-level administrative links across the top of the screen. Below that, the Toolbar module has a drawer section where it displays links provided by other modules, such as the core Shortcut module. The drawer can be hidden/shown by clicking on its corresponding tab.', array('@shortcuts-help' => url('admin/help/shortcut'))) . '
';
$output .= '
';
return $output;
}
@@ -43,9 +43,6 @@ function toolbar_theme($existing, $type, $theme, $path) {
'render element' => 'toolbar',
'template' => 'toolbar',
);
- $items['toolbar_tray'] = array(
- 'render element' => 'element',
- );
return $items;
}
@@ -75,13 +72,34 @@ function toolbar_pre_render($toolbar) {
}
/**
- * Implements hook_preprocess_HOOK() for toolbar.tpl.php.
- *
- * Adding the 'overlay-displace-top' class to the toolbar pushes the overlay
- * down, so it appears below the toolbar.
+ * Implements hook_preprocess_HOOK().
*/
function toolbar_preprocess_toolbar(&$variables) {
- $variables['attributes']['class'][] = "overlay-displace-top";
+ // Metadata for the toolbar wrapping element.
+ $variables['attributes'] = new Attribute(array(
+ 'id' => 'toolbar',
+ // The 'overlay-displace-top' class pushes the overlay down, so it appears
+ // below the toolbar.
+ 'class' => array('toolbar', 'overlay-displace-top'),
+ 'role' => 'navigation'
+ ));
+
+ // Provide a convenience variable for the themed tabs.
+ $variables['tabs'] = $variables['toolbar']['tabs'];
+
+ // Place the tabs in a top-level variable so that attribute information
+ // can be associated with each one.
+ foreach ($variables['toolbar']['trays'] as $key => $tray) {
+ $variables['trays'][$key] = array(
+ 'content' => $variables['toolbar']['trays'][$key],
+ 'attributes' => new Attribute(array(
+ 'id' => 'toolbar-tray-' . $key,
+ 'class' => array('tray', $key),
+ 'data-toolbar-tray' => $key,
+ )
+ ),
+ );
+ }
}
/**
@@ -155,8 +173,8 @@ function toolbar_toolbar() {
*
* @return
* A renderable arrray, with two children:
- * - 'toolbar_tabs': an array of links, rendered by theme('links').
- * - 'toolbar_tray': an array of render elements, at moat one of which is
+ * - 'tabs': an array of links, rendered by theme('links').
+ * - 'trays': an array of render elements, at moat one of which is
* displayed at once, when the corresponding tab is activated. The trays
* are rendered by theme('toolbar_tray').
*/
@@ -165,7 +183,7 @@ function toolbar_view() {
$build = array('#theme' => 'toolbar');
$build['#attached']['library'][] = array('toolbar', 'toolbar');
- // Get the configured breakpoint for switch from vertical to horizontal
+ // Get the configured breakpoint to switch from vertical to horizontal
// toolbar presentation.
$breakpoints = entity_load('breakpoint_group', 'module.toolbar.toolbar');
if (!empty($breakpoints)) {
@@ -174,7 +192,6 @@ function toolbar_view() {
function($object) {return $object->mediaQuery;},
$breakpoints->breakpoints);
- $build['#attached']['js'] = array();
$build['#attached']['js'][] = array(
'data' => $media_queries,
'type' => 'setting',
@@ -192,19 +209,26 @@ function($object) {return $object->mediaQuery;},
uasort($toolbar_groups, 'drupal_sort_weight');
// Build the tabs and trays from the toolbar groups.
- $toolbar_tabs = array();
- $toolbar_trays = array();
+ $build['trays'] = array();
+ $build['tabs'] = array(
+ '#theme' => 'links',
+ '#links' => array(),
+ '#attributes' => array(
+ 'class' => array('bar', 'clearfix'),
+ ),
+ '#heading' => array('text' => t('Drupal toolbar'), 'level' => 'h2', 'class' => 'element-invisible'),
+ );
$tab_defaults = array(
'title' => '',
'href' => '',
'html' => FALSE,
- 'attributes' => array(),
+ 'attributes' => new Attribute(),
);
foreach ($toolbar_groups as $category => $items) {
if ($tab = $items['tab']) {
// Log a warning if the tab is already defined.
- if (array_key_exists($category, $toolbar_tabs)) {
+ if (array_key_exists($category, $build['tabs']['#links'])) {
watchdog('toolbar', 'Toolbar tab %category is already defined.',
array('%category' => $category)
);
@@ -220,39 +244,20 @@ function($object) {return $object->mediaQuery;},
$tab['attributes']['data-toolbar-tray'] = $category;
$tab['attributes']['role'] = 'button';
- $toolbar_tabs[$category] = $tab;
+ // Assign the tabs to the build.
+ $build['tabs']['#links'][$category] = $tab;
}
if (!empty($items['tray'])) {
- if (array_key_exists($category, $toolbar_trays)) {
- array_merge($toolbar_trays[$category], $items['tray']);
+ if (array_key_exists($category, $build['trays'])) {
+ array_merge($build['trays'][$category], $items['tray']);
}
else {
- $toolbar_trays[$category] = $items['tray'];
+ // Assign the tray to the build.
+ $build['trays'][$category] = $items['tray'];
}
}
}
- // Assign the tabs to the build.
- $build['toolbar_tabs'] = array(
- '#theme' => 'links',
- '#links' => $toolbar_tabs,
- '#attributes' => array(
- 'class' => array('bar', 'clearfix'),
- ),
- '#heading' => array('text' => t('Drupal toolbar'), 'level' => 'h2', 'class' => 'element-invisible'),
- );
-
- // Assign the trays to the build.
- $build['toolbar_trays'] = array();
- foreach ($toolbar_trays as $key => $tray) {
- if (!isset($tray['#theme_wrappers'])) {
- $tray['#theme_wrappers'] = array();
- }
- $tray['#theme_wrappers'][] = 'toolbar_tray';
- $tray['#name'] = $key;
- $build['toolbar_trays'][$key] = $tray;
- }
-
return $build;
}
@@ -297,25 +302,6 @@ function toolbar_menu_navigation_links(&$tree) {
}
/**
- * Preprocess variables for theme_toolbar_tray().
- */
-function template_preprocess_toolbar_tray(&$variables) {
- $name = $variables['element']['#name'];
- // Provide a content property to easily reference the rendered content
- // of the tray.
- $variables['content'] = $variables['element']['#children'];
- $variables['attributes'] = array(
- 'id' => 'toolbar-tray-' . $name,
- 'class' => array(
- 'tray',
- $name,
- ),
- 'data-toolbar-tray' => $name,
- );
- $variables['theme_hook_suggestions'][] = 'toolbar_tray__' . $name;
-}
-
-/**
* Returns HTML for wrapping content in a toolbar tray.
*
* @param array $variables
@@ -323,13 +309,6 @@ function template_preprocess_toolbar_tray(&$variables) {
* - attributes: Associative array of attributes to be placed in the nav tag.
* - content: The rendered content of the toolbar tray.
*/
-function theme_toolbar_tray($variables) {
- $output = '';
- return $output;
-}
/**
* Checks whether an item is in the active trail.