function hook_toolbar

Add items to the Toolbar menu.

The Toolbar has two parts. The tabs are menu links, rendered by theme_links(), that are displayed if the module is enabled and the user has the 'access toolbar' permission. The trays are render elements, usually lists of links, and each tray corresponds to a tab. When a tab is activated, the corresponding tray is displayed; only one tab can be activated at a time. If a tab does not have a corresponding tray, or if javascript is disabled, then the tab is simply a link.

This hook is invoked in toolbar_view().

Return value

An array of toolbar items, keyed by unique identifiers such as 'home' or 'administration', or the short name of the module implementing the hook. The corresponding value is an associative array that may contain the following key-value pairs:

  • 'tab': Required, unless the item is adding links to an existing tab. An

array with keys 'title', 'href', 'html', and 'attributes', as used by theme_links(). The 'href' value is ignored unless 'tray' (below) is omitted, or if javascript is disabled.

  • 'tray': Optional. A render element that is displayed when the tab is activated.
  • 'weight': Optional. Integer weight used for sorting tabs.

See also

toolbar_view()

Related topics

5 functions implement hook_toolbar()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

shortcut_toolbar in drupal/core/modules/shortcut/shortcut.module
Implements hook_toolbar().
template_preprocess_toolbar in drupal/core/modules/toolbar/toolbar.module
Implements template_preprocess_HOOK().
toolbar_test_toolbar in drupal/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module
Um
toolbar_toolbar in drupal/core/modules/toolbar/toolbar.module
Implements hook_toolbar().
user_toolbar in drupal/core/modules/user/user.module
Implements hook_toolbar().
1 invocation of hook_toolbar()
toolbar_view in drupal/core/modules/toolbar/toolbar.module
Builds the Toolbar as a structured array ready for drupal_render().

File

drupal/core/modules/toolbar/toolbar.api.php, line 42
Hooks provided by the Toolbar module.

Code

function hook_toolbar() {
  $items = array();

  // The 'Home' tab is a simple link, with no corresponding tray.
  $items['home'] = array(
    'tab' => array(
      'title' => t('Home'),
      'href' => '<front>',
      'html' => FALSE,
      'attributes' => array(
        'title' => t('Home page'),
      ),
    ),
    'weight' => -10,
  );

  /**
   * A tab may be associated with a tray.
   *
   * The tray should contain a renderable array. An option #heading property
   * can be passed. The text is written to a heading tag in the tray as a
   * landmark for accessibility. A default heading will be created if one is not
   * passed.
   */
  $items['commerce'] = array(
    'tab' => array(
      'title' => t('Shopping cart'),
      'href' => '',
      'html' => FALSE,
      'attributes' => array(
        'title' => t('Shopping cart'),
      ),
    ),
    'tray' => array(
      '#heading' => t('Shopping cart actions'),
      'content' => array(
        '#theme' => 'item_list',
        '#items' => array(),
      ),
    ),
    'weight' => 50,
  );
  return $items;
}