2 * Implements hook_toolbar().
4 function {{ machine_name }}_toolbar() {
7 // Add a search field to the toolbar. The search field employs no toolbar
8 // module theming functions.
9 $items['global_search'] = [
10 '#type' => 'toolbar_item',
14 'placeholder' => t('Search the site'),
15 'class' => ['search-global'],
19 // Custom CSS, JS or a library can be associated with the toolbar item.
27 // The 'Home' tab is a simple link, which is wrapped in markup associated
28 // with a visual tab styling.
30 '#type' => 'toolbar_item',
33 '#title' => t('Home'),
34 '#url' => Url::fromRoute('<front>'),
37 'title' => t('Home page'),
38 'class' => ['toolbar-icon', 'toolbar-icon-home'],
45 // A tray may be associated with a tab.
47 // When the tab is activated, the tray will become visible, either in a
48 // horizontal or vertical orientation on the screen.
50 // The tray should contain a renderable array. An optional #heading property
51 // can be passed. This text is written to a heading tag in the tray as a
52 // landmark for accessibility.
53 $items['commerce'] = [
54 '#type' => 'toolbar_item',
57 '#title' => t('Shopping cart'),
58 '#url' => Url::fromRoute('cart'),
61 'title' => t('Shopping cart'),
66 '#heading' => t('Shopping cart actions'),
68 '#theme' => 'item_list',
69 '#items' => [/* An item list renderable array */],
75 // The tray can be used to render arbitrary content.
77 // A renderable array passed to the 'tray' property will be rendered outside
78 // the administration bar but within the containing toolbar element.
80 // If the default behavior and styling of a toolbar tray is not desired, one
81 // can render content to the toolbar element and apply custom theming and
83 $items['user_messages'] = [
84 // Include the toolbar_tab_wrapper to style the link like a toolbar tab.
85 // Exclude the theme wrapper if custom styling is desired.
86 '#type' => 'toolbar_item',
89 '#theme' => 'user_message_toolbar_tab',
90 '#theme_wrappers' => [],
91 '#title' => t('Messages'),
92 '#url' => Url::fromRoute('user.message'),
95 'title' => t('Messages'),
100 '#heading' => t('User messages'),
101 'messages' => [/* renderable content */],