Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / HookMenuAlter.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
4
5 use Drupal\drupalmoduleupgrader\ConverterBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Pharborist\Functions\ParameterNode;
8
9 /**
10  * @Converter(
11  *  id = "hook_menu_alter",
12  *  description = @Translation("Creates boilerplate for logic that formerly belonged in hook_menu_alter()."),
13  *  hook = "hook_menu_alter",
14  *  fixme = @Translation("hook_menu_alter() is gone in Drupal 8. You will have to port its
15 functionality manually. The are several mechanisms for this:
16
17 To alter routes, you must implement a route subscriber class. An empty one
18 has been generated for you in src/Routing/RouteSubscriber.php.
19
20 To alter menu link definitions, see hook_menu_links_discovered_alter(). An
21 empty implementation has been created at the end of this file.
22
23 To alter local task definitions, see hook_menu_local_tasks_alter(). An
24 empty implementation has been created for you at the end of this file.
25
26 To alter local actions, see hook_menu_local_actions_alter(). An
27 empty implementation has been created for you at the end of this file.
28
29 Contextual links are altered during rendering only. See
30 hook_contextual_links_view_alter(). An empty implementation has been
31 created for you at the end of this file."),
32  *  documentation = {
33  *    "https://www.drupal.org/node/2118147#alter",
34  *    "https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Menu%21menu.api.php/function/hook_menu_links_discovered_alter/8",
35  *    "https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Menu%21menu.api.php/function/hook_menu_local_tasks_alter/8",
36  *    "https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Menu%21menu.api.php/function/hook_menu_local_actions_alter/8",
37  *    "https://api.drupal.org/api/drupal/core%21modules%21contextual%21contextual.api.php/function/hook_contextual_links_view_alter/8",
38  *  }
39  * )
40  */
41 class HookMenuAlter extends ConverterBase {
42
43   /**
44    * {@inheritdoc}
45    */
46   public function convert(TargetInterface $target) {
47     $target
48       ->getIndexer('function')
49       ->get($this->pluginDefinition['hook'])
50       ->setDocComment($this->buildFixMe(NULL, [], self::DOC_COMMENT));
51
52     $render = [
53       '#theme' => 'dmu_route_subscriber',
54       '#module' => $target->id(),
55     ];
56     $this->writeClass($target, $this->parse($render));
57
58     $alterable = ParameterNode::create('data');
59     $alterable->setTypeHint('array')->setReference(TRUE);
60
61     $parameter = clone $alterable;
62     $this
63       ->implement($target, 'menu_links_discovered_alter')
64       ->appendParameter($parameter->setName('links'));
65
66     $parameter = clone $alterable;
67     $this
68       ->implement($target, 'menu_local_tasks_alter')
69       ->appendParameter($parameter->setName('data'))
70       ->appendParameter(ParameterNode::create('route_name'));
71
72     $parameter = clone $alterable;
73     $this
74       ->implement($target, 'menu_local_actions_alter')
75       ->appendParameter($parameter->setName('local_actions'));
76
77     $parameter = clone $alterable;
78     $items = clone $alterable;
79     $function = $this
80       ->implement($target, 'contextual_links_view_alter')
81       ->appendParameter($parameter->setName('element'))
82       ->appendParameter($items->setName('items')->setReference(FALSE));
83
84     $target->save($function);
85   }
86
87 }