function toolbar_pre_render

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.

Parameters

array $element: A renderable array.

Return value

A renderable array.

See also

toolbar_page_build().

1 string reference to 'toolbar_pre_render'
toolbar_element_info in drupal/core/modules/toolbar/toolbar.module
Implements hook_element_info().

File

drupal/core/modules/toolbar/toolbar.module, line 186
Administration toolbar for quick access to top level administration items.

Code

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;
}