29fbe5ffda3fcdbc3b952c9c314ea9ac46f3ed96
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / toolbar.twig
1 /**
2  * Implements hook_toolbar().
3  */
4 function {{ machine_name }}_toolbar() {
5   $items = [];
6
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',
11     'tab' => [
12       '#type' => 'search',
13       '#attributes' => [
14         'placeholder' => t('Search the site'),
15         'class' => ['search-global'],
16       ],
17     ],
18     '#weight' => 200,
19     // Custom CSS, JS or a library can be associated with the toolbar item.
20     '#attached' => [
21       'library' => [
22         'search/global',
23       ],
24     ],
25   ];
26
27   // The 'Home' tab is a simple link, which is wrapped in markup associated
28   // with a visual tab styling.
29   $items['home'] = [
30     '#type' => 'toolbar_item',
31     'tab' => [
32       '#type' => 'link',
33       '#title' => t('Home'),
34       '#url' => Url::fromRoute('<front>'),
35       '#options' => [
36         'attributes' => [
37           'title' => t('Home page'),
38           'class' => ['toolbar-icon', 'toolbar-icon-home'],
39         ],
40       ],
41     ],
42     '#weight' => -20,
43   ];
44
45   // A tray may be associated with a tab.
46   //
47   // When the tab is activated, the tray will become visible, either in a
48   // horizontal or vertical orientation on the screen.
49   //
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',
55     'tab' => [
56       '#type' => 'link',
57       '#title' => t('Shopping cart'),
58       '#url' => Url::fromRoute('cart'),
59       '#options' => [
60         'attributes' => [
61           'title' => t('Shopping cart'),
62         ],
63       ],
64     ],
65     'tray' => [
66       '#heading' => t('Shopping cart actions'),
67       'shopping_cart' => [
68         '#theme' => 'item_list',
69         '#items' => [/* An item list renderable array */],
70       ],
71     ],
72     '#weight' => 150,
73   ];
74
75   // The tray can be used to render arbitrary content.
76   //
77   // A renderable array passed to the 'tray' property will be rendered outside
78   // the administration bar but within the containing toolbar element.
79   //
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
82   // behaviors.
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',
87     'tab' => [
88       '#type' => 'link',
89       '#theme' => 'user_message_toolbar_tab',
90       '#theme_wrappers' => [],
91       '#title' => t('Messages'),
92       '#url' => Url::fromRoute('user.message'),
93       '#options' => [
94         'attributes' => [
95           'title' => t('Messages'),
96         ],
97       ],
98     ],
99     'tray' => [
100       '#heading' => t('User messages'),
101       'messages' => [/* renderable content */],
102     ],
103     '#weight' => 125,
104   ];
105
106   return $items;
107 }