Builds the Toolbar as a structured array ready for drupal_render().
A renderable arrray, with two children:
function toolbar_view() {
$build = array(
'#theme' => 'toolbar',
);
$build['#attached']['library'][] = array(
'toolbar',
'toolbar',
);
// Get the configured breakpoint to 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(
'data' => $media_queries,
'type' => 'setting',
);
// // Load the breakpoints for toolbar.
foreach ($breakpoints->breakpoints as $key => $breakpoint) {
$build['#attached']['js'][0]['data']['toolbar']['breakpoints'][$key] = $breakpoint->mediaQuery;
}
}
// Get toolbar items 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.
$build['trays'] = array();
$build['tabs'] = array(
'#theme' => 'links',
'#links' => array(),
'#attributes' => array(
'class' => array(
'bar',
'clearfix',
),
),
'#heading' => array(
'text' => t('Toolbar'),
'level' => 'h2',
'class' => 'element-invisible',
),
);
$tab_defaults = array(
'title' => '',
'href' => '',
'html' => FALSE,
'attributes' => new Attribute(),
);
foreach ($toolbar_groups as $group => $items) {
if ($tab = $items['tab']) {
// Merge in the defaults.
$tab += $tab_defaults;
}
// Register a tray if one is associated with this tab.
if (!empty($items['tray'])) {
// Provide an id, a data attribute linking each tab to the corresponding
// tray and aria information.
$tab['attributes']['id'] = 'toolbar-tab-' . $group;
$tab['attributes']['data-toolbar-tray'] = $group;
$tab['attributes']['aria-owns'] = 'toolbar-tray-' . $group;
$tab['attributes']['role'] = 'button';
$tab['attributes']['aria-pressed'] = 'false';
if (array_key_exists($group, $build['trays'])) {
array_merge($build['trays'][$group], $items['tray']);
}
else {
// Assign the tray to the build.
$build['trays'][$group] = $items['tray'];
}
}
// Assign the tabs to the build.
$build['tabs']['#links'][$group] = $tab;
}
return $build;
}