1 admin_bar.api.php hook_admin_bar_output_build(&$content)

Add to the administration bar content before it is rendered.

Only use this hook to add new data to the menu structure. Use hook_admin_bar_output_alter() to *alter* existing data.


array $content: A structured array suitable for backdrop_render(), potentially containing:

  • menu: The administrative bar of links below the path 'admin/*'.
  • icon: The icon menu.
  • account: The user account name and log out link.
  • users: The user counter.

Additionally, these special properties:

  • #components: The actual components contained in $content are configurable and depend on the 'admin_bar.settings.components' configuration value. #components holds a copy of that for convenience.
  • #complete: A Boolean indicating whether the complete menu should be built, ignoring the current configuration in #components.

Passed by reference.

See also







core/modules/admin_bar/admin_bar.api.php, line 66
API documentation for Administration bar.


function hook_admin_bar_output_build(&$content) {
  // In case your implementation provides a configurable component, check
  // whether the component should be displayed:
  if (in_array('shortcut.links', $content['#components']) && !$content['#complete']) {

  // Add new top-level item to the menu.
  if (isset($content['menu']['menu'])) {
    $content['menu']['menu']['myitem'] = array(
      '#title' => t('My item'),
      // #attributes are used for list items (LI).
      '#attributes' => array('class' => array('my_module-myitem')),
      '#href' => 'my_module/path',
      // #options are passed to l().
      '#options' => array(
        'query' => backdrop_get_destination(),
        // Apply a class on the link (anchor).
        'attributes' => array('class' => array('myitem-link-anchor')),
      // #weight controls the order of links in the resulting item list.
      '#weight' => 50,
  // Add link to the icon menu to manually run cron.
  if (isset($content['icon'])) {
    $content['icon']['myitem']['cron'] = array(
      '#title' => t('Run cron'),
      '#access' => user_access('administer site configuration'),
      '#href' => 'admin/reports/status/run-cron',