Backup of db before drupal security update
[yaffs-website] / web / core / includes / menu.inc
1 <?php
2
3 /**
4  * @file
5  * API for the Drupal menu system.
6  */
7
8 /**
9  * @addtogroup menu
10  * @{
11  */
12
13 use Drupal\Component\Utility\SafeMarkup;
14 use Drupal\Core\Render\Element;
15
16
17 /**
18  * Prepares variables for single local task link templates.
19  *
20  * Default template: menu-local-task.html.twig.
21  *
22  * @param array $variables
23  *   An associative array containing:
24  *   - element: A render element containing:
25  *     - #link: A menu link array with 'title', 'url', and (optionally)
26  *       'localized_options' keys.
27  *     - #active: A boolean indicating whether the local task is active.
28  */
29 function template_preprocess_menu_local_task(&$variables) {
30   $link = $variables['element']['#link'];
31   $link += [
32     'localized_options' => [],
33   ];
34   $link_text = $link['title'];
35
36   if (!empty($variables['element']['#active'])) {
37     $variables['is_active'] = TRUE;
38
39     // Add text to indicate active tab for non-visual users.
40     $active = SafeMarkup::format('<span class="visually-hidden">@label</span>', ['@label' => t('(active tab)')]);
41     $link_text = t('@local-task-title@active', ['@local-task-title' => $link_text, '@active' => $active]);
42   }
43
44   $link['localized_options']['set_active_class'] = TRUE;
45
46   $variables['link'] = [
47     '#type' => 'link',
48     '#title' => $link_text,
49     '#url' => $link['url'],
50     '#options' => $link['localized_options'],
51   ];
52 }
53
54 /**
55  * Prepares variables for single local action link templates.
56  *
57  * Default template: menu-local-action.html.twig.
58  *
59  * @param array $variables
60  *   An associative array containing:
61  *   - element: A render element containing:
62  *     - #link: A menu link array with 'title', 'url', and (optionally)
63  *       'localized_options' keys.
64  */
65 function template_preprocess_menu_local_action(&$variables) {
66   $link = $variables['element']['#link'];
67   $link += [
68     'localized_options' => [],
69   ];
70   $link['localized_options']['attributes']['class'][] = 'button';
71   $link['localized_options']['attributes']['class'][] = 'button-action';
72   $link['localized_options']['set_active_class'] = TRUE;
73
74   $variables['link'] = [
75     '#type' => 'link',
76     '#title' => $link['title'],
77     '#options' => $link['localized_options'],
78     '#url' => $link['url'],
79   ];
80 }
81
82 /**
83  * Returns an array containing the names of system-defined (default) menus.
84  */
85 function menu_list_system_menus() {
86   return [
87     'tools' => 'Tools',
88     'admin' => 'Administration',
89     'account' => 'User account menu',
90     'main' => 'Main navigation',
91     'footer' => 'Footer menu',
92   ];
93 }
94
95 /**
96  * Collects the local tasks (tabs) for the current route.
97  *
98  * @param int $level
99  *   The level of tasks you ask for. Primary tasks are 0, secondary are 1.
100  *
101  * @return array
102  *   An array containing
103  *   - tabs: Local tasks for the requested level.
104  *   - route_name: The route name for the current page used to collect the local
105  *     tasks.
106  *
107  * @see hook_menu_local_tasks_alter()
108  *
109  * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
110  */
111 function menu_local_tasks($level = 0) {
112   /** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */
113   $manager = \Drupal::service('plugin.manager.menu.local_task');
114   return $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), $level);
115 }
116
117 /**
118  * Returns the rendered local tasks at the top level.
119  *
120  * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
121  */
122 function menu_primary_local_tasks() {
123   /** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */
124   $manager = \Drupal::service('plugin.manager.menu.local_task');
125   $links = $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), 0);
126   // Do not display single tabs.
127   return count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : '';
128 }
129
130 /**
131  * Returns the rendered local tasks at the second level.
132  *
133  * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
134  */
135 function menu_secondary_local_tasks() {
136   /** @var \Drupal\Core\Menu\LocalTaskManagerInterface $manager */
137   $manager = \Drupal::service('plugin.manager.menu.local_task');
138   $links = $manager->getLocalTasks(\Drupal::routeMatch()->getRouteName(), 1);
139   // Do not display single tabs.
140   return count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : '';
141 }
142
143 /**
144  * Returns a renderable element for the primary and secondary tabs.
145  */
146 function menu_local_tabs() {
147   $build = [
148     '#theme' => 'menu_local_tasks',
149     '#primary' => menu_primary_local_tasks(),
150     '#secondary' => menu_secondary_local_tasks(),
151   ];
152   return !empty($build['#primary']) || !empty($build['#secondary']) ? $build : [];
153 }
154
155 /**
156  * Clears all cached menu data.
157  *
158  * This should be called any time broad changes
159  * might have been made to the router items or menu links.
160  */
161 function menu_cache_clear_all() {
162   \Drupal::cache('menu')->invalidateAll();
163 }
164
165 /**
166  * @} End of "addtogroup menu".
167  */