Builds the Toolbar as a structured array ready for drupal_render().
Since building the toolbar takes some time, it is done just prior to rendering to ensure that it is built only if it will be displayed.
array $element: A renderable array.
A renderable array.
function toolbar_pre_render($element) {
// Get the configured breakpoints 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);
$element['#attached']['js'][] = array(
'data' => $media_queries,
'type' => 'setting',
);
}
// Get toolbar items from all modules that implement hook_toolbar().
$items = module_invoke_all('toolbar');
// Allow for altering of hook_toolbar().
drupal_alter('toolbar', $items);
// Sort the children.
uasort($items, 'element_sort');
// Merge in the original toolbar values.
$element = array_merge($element, $items);
// Render the children.
$element['#children'] = drupal_render_children($element);
return $element;
}