3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
5 use Drupal\drupalmoduleupgrader\ConverterBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Pharborist\Functions\ParameterNode;
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:
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.
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.
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.
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.
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."),
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",
41 class HookMenuAlter extends ConverterBase {
46 public function convert(TargetInterface $target) {
48 ->getIndexer('function')
49 ->get($this->pluginDefinition['hook'])
50 ->setDocComment($this->buildFixMe(NULL, [], self::DOC_COMMENT));
53 '#theme' => 'dmu_route_subscriber',
54 '#module' => $target->id(),
56 $this->writeClass($target, $this->parse($render));
58 $alterable = ParameterNode::create('data');
59 $alterable->setTypeHint('array')->setReference(TRUE);
61 $parameter = clone $alterable;
63 ->implement($target, 'menu_links_discovered_alter')
64 ->appendParameter($parameter->setName('links'));
66 $parameter = clone $alterable;
68 ->implement($target, 'menu_local_tasks_alter')
69 ->appendParameter($parameter->setName('data'))
70 ->appendParameter(ParameterNode::create('route_name'));
72 $parameter = clone $alterable;
74 ->implement($target, 'menu_local_actions_alter')
75 ->appendParameter($parameter->setName('local_actions'));
77 $parameter = clone $alterable;
78 $items = clone $alterable;
80 ->implement($target, 'contextual_links_view_alter')
81 ->appendParameter($parameter->setName('element'))
82 ->appendParameter($items->setName('items')->setReference(FALSE));
84 $target->save($function);