Chris@0: 'toolbar_item', Chris@0: 'tab' => [ Chris@0: '#type' => 'search', Chris@0: '#attributes' => [ Chris@0: 'placeholder' => t('Search the site'), Chris@0: 'class' => ['search-global'], Chris@0: ], Chris@0: ], Chris@0: '#weight' => 200, Chris@0: // Custom CSS, JS or a library can be associated with the toolbar item. Chris@0: '#attached' => [ Chris@0: 'library' => [ Chris@0: 'search/global', Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: Chris@0: // The 'Home' tab is a simple link, which is wrapped in markup associated Chris@0: // with a visual tab styling. Chris@0: $items['home'] = [ Chris@0: '#type' => 'toolbar_item', Chris@0: 'tab' => [ Chris@0: '#type' => 'link', Chris@0: '#title' => t('Home'), Chris@0: '#url' => Url::fromRoute(''), Chris@0: '#options' => [ Chris@0: 'attributes' => [ Chris@0: 'title' => t('Home page'), Chris@0: 'class' => ['toolbar-icon', 'toolbar-icon-home'], Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: '#weight' => -20, Chris@0: ]; Chris@0: Chris@0: // A tray may be associated with a tab. Chris@0: // Chris@0: // When the tab is activated, the tray will become visible, either in a Chris@0: // horizontal or vertical orientation on the screen. Chris@0: // Chris@0: // The tray should contain a renderable array. An optional #heading property Chris@0: // can be passed. This text is written to a heading tag in the tray as a Chris@0: // landmark for accessibility. Chris@0: $items['commerce'] = [ Chris@0: '#type' => 'toolbar_item', Chris@0: 'tab' => [ Chris@0: '#type' => 'link', Chris@0: '#title' => t('Shopping cart'), Chris@0: '#url' => Url::fromRoute('cart'), Chris@0: '#options' => [ Chris@0: 'attributes' => [ Chris@0: 'title' => t('Shopping cart'), Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: 'tray' => [ Chris@0: '#heading' => t('Shopping cart actions'), Chris@0: 'shopping_cart' => [ Chris@0: '#theme' => 'item_list', Chris@0: '#items' => [/* An item list renderable array */], Chris@0: ], Chris@0: ], Chris@0: '#weight' => 150, Chris@0: ]; Chris@0: Chris@0: // The tray can be used to render arbitrary content. Chris@0: // Chris@0: // A renderable array passed to the 'tray' property will be rendered outside Chris@0: // the administration bar but within the containing toolbar element. Chris@0: // Chris@0: // If the default behavior and styling of a toolbar tray is not desired, one Chris@0: // can render content to the toolbar element and apply custom theming and Chris@0: // behaviors. Chris@0: $items['user_messages'] = [ Chris@0: // Include the toolbar_tab_wrapper to style the link like a toolbar tab. Chris@0: // Exclude the theme wrapper if custom styling is desired. Chris@0: '#type' => 'toolbar_item', Chris@0: 'tab' => [ Chris@0: '#type' => 'link', Chris@0: '#theme' => 'user_message_toolbar_tab', Chris@0: '#theme_wrappers' => [], Chris@0: '#title' => t('Messages'), Chris@0: '#url' => Url::fromRoute('user.message'), Chris@0: '#options' => [ Chris@0: 'attributes' => [ Chris@0: 'title' => t('Messages'), Chris@0: ], Chris@0: ], Chris@0: ], Chris@0: 'tray' => [ Chris@0: '#heading' => t('User messages'), Chris@0: 'messages' => [/* renderable content */], Chris@0: ], Chris@0: '#weight' => 125, Chris@0: ]; Chris@0: Chris@0: return $items; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Alter the toolbar menu after hook_toolbar() is invoked. Chris@0: * Chris@12: * This hook is invoked by Toolbar::preRenderToolbar() immediately after Chris@12: * hook_toolbar(). The toolbar definitions are passed in by reference. Each Chris@12: * element of the $items array is one item returned by a module from Chris@12: * hook_toolbar(). Additional items may be added, or existing items altered. Chris@0: * Chris@0: * @param $items Chris@0: * Associative array of toolbar menu definitions returned from hook_toolbar(). Chris@0: */ Chris@0: function hook_toolbar_alter(&$items) { Chris@0: // Move the User tab to the right. Chris@0: $items['commerce']['#weight'] = 5; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup hooks". Chris@0: */