diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 6c5afb4..5c497b0 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -159,6 +159,10 @@ function toolbar_pre_render($toolbar) { /** * Implements template_preprocess_HOOK(). + * + * The toolbar render array is built from hook_toolbar() as an array of items; + * each item has a tab and an optional tray. We need to separate the tabs from + * the trays to get the positioning to work. */ function template_preprocess_toolbar(&$variables) { // Metadata for the toolbar wrapping element. @@ -185,13 +189,11 @@ function template_preprocess_toolbar(&$variables) { $variables['trays'] = array(); // Loop through the items. Pull out trays if defined under the #tray key. foreach($variables['elements']['#items'] as $key => $item) { - $id = drupal_html_class($key); - $variables['bar']['items'][$key] = $item; - $variables['bar']['items'][$key]['#toolbar_identifier'] = $id; - if (in_array('#tray', array_keys($item)) && isset($item['#tray'])) { + if (isset($item['#tray'])) { $variables['trays'][$key] = $item['#tray']; - $variables['trays'][$key]['#toolbar_identifier'] = $id; + unset($item['#tray']); } + $variables['bar']['items'][$key] = $item; } unset($variables['elements']['#items']); } @@ -385,6 +387,7 @@ function toolbar_toolbar() { /** * Builds the Toolbar as a structured array ready for drupal_render(). * + * @todo: Update this doc block. * @return * A renderable arrray, with two children: * - 'tabs': an array of render elements, with default type 'link'. @@ -416,6 +419,17 @@ function ($object) { // Get toolbar items from all modules that implement hook_toolbar(). $toolbar_items = module_invoke_all('toolbar'); + + // Add properties to associate each tab with its (optional) tray. + foreach ($toolbar_items as $key => &$item) { + $id = drupal_html_class($key); + $item['#toolbar_identifier'] = $id; + if (isset($item['#tray'])) { + $item['#tray']['#toolbar_identifier'] = $id; + } + } + unset($item); + // Allow for altering of hook_toolbar(). drupal_alter('toolbar', $toolbar_items);