Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / modules / menu_test / menu_test.module
1 <?php
2
3 /**
4  * @file
5  * Module that implements various hooks for menu tests.
6  */
7
8 use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
9 use Drupal\Core\Url;
10
11 /**
12  * Implements hook_menu_links_discovered_alter().
13  */
14 function menu_test_menu_links_discovered_alter(&$links) {
15   // Many of the machine names here are slightly different from the route name.
16   // Since the machine name is arbitrary, this helps ensure that core does not
17   // add mistaken assumptions about the correlation.
18   $links['menu_test.menu_name_test']['menu_name'] = menu_test_menu_name();
19   $links['menu_test.context']['title'] = \Drupal::config('menu_test.menu_item')->get('title');
20
21   // Adds a custom menu link.
22   $links['menu_test.custom'] = [
23     'title' => 'Custom link',
24     'route_name' => 'menu_test.custom',
25     'description' => 'Custom link used to check the integrity of manually added menu links.',
26     'parent' => 'menu_test',
27   ];
28 }
29
30 /**
31  * Implements hook_menu_local_tasks_alter().
32  */
33 function menu_test_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) {
34   if (in_array($route_name, ['menu_test.tasks_default'])) {
35     $data['tabs'][0]['foo'] = [
36       '#theme' => 'menu_local_task',
37       '#link' => [
38         'title' => "Task 1 <script>alert('Welcome to the jungle!')</script>",
39         'url' => Url::fromRoute('menu_test.router_test1', ['bar' => '1']),
40       ],
41       '#weight' => 10,
42     ];
43     $data['tabs'][0]['bar'] = [
44       '#theme' => 'menu_local_task',
45       '#link' => [
46         'title' => 'Task 2',
47         'url' => Url::fromRoute('menu_test.router_test2', ['bar' => '2']),
48       ],
49       '#weight' => 20,
50     ];
51   }
52   $cacheability->addCacheTags(['kittens:dwarf-cat']);
53 }
54
55 /**
56  * Sets a static variable for the testMenuName() test.
57  *
58  * Used to change the menu_name parameter of a menu.
59  *
60  * @param string $new_name
61  *   (optional) If set, will change the $menu_name value.
62  *
63  * @return string
64  *   The $menu_name value to use.
65  */
66 function menu_test_menu_name($new_name = '') {
67   static $menu_name = 'original';
68   if ($new_name) {
69     $menu_name = $new_name;
70   }
71   return $menu_name;
72 }
73
74 /**
75  * Title callback: Concatenates the title and case number.
76  *
77  * @param string $title
78  *   Title string.
79  * @param int $case_number
80  *   (optional) The current case number which it tests (defaults to 3).
81  *
82  * @return string
83  *   A string containing the title and case number.
84  *
85  * @see menu_test_menu()
86  */
87 function menu_test_title_callback($title, $case_number = 3) {
88   return t($title) . ' - Case ' . $case_number;
89 }