5 * Module that implements various hooks for menu tests.
8 use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
12 * Implements hook_menu_links_discovered_alter().
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');
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',
31 * Implements hook_menu_local_tasks_alter().
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',
38 'title' => "Task 1 <script>alert('Welcome to the jungle!')</script>",
39 'url' => Url::fromRoute('menu_test.router_test1', ['bar' => '1']),
43 $data['tabs'][0]['bar'] = [
44 '#theme' => 'menu_local_task',
47 'url' => Url::fromRoute('menu_test.router_test2', ['bar' => '2']),
52 $cacheability->addCacheTags(['kittens:dwarf-cat']);
56 * Sets a static variable for the testMenuName() test.
58 * Used to change the menu_name parameter of a menu.
60 * @param string $new_name
61 * (optional) If set, will change the $menu_name value.
64 * The $menu_name value to use.
66 function menu_test_menu_name($new_name = '') {
67 static $menu_name = 'original';
69 $menu_name = $new_name;
75 * Title callback: Concatenates the title and case number.
77 * @param string $title
79 * @param int $case_number
80 * (optional) The current case number which it tests (defaults to 3).
83 * A string containing the title and case number.
85 * @see menu_test_menu()
87 function menu_test_title_callback($title, $case_number = 3) {
88 return t($title) . ' - Case ' . $case_number;