5 * Allows administrators to create custom menu links.
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\system\MenuInterface;
12 * Implements hook_help().
14 function menu_link_content_help($route_name, RouteMatchInterface $route_match) {
15 switch ($route_name) {
16 case 'help.page.menu_link_content':
18 $output .= '<h3>' . t('About') . '</h3>';
19 $output .= '<p>' . t('The Custom Menu Links module allows users to create menu links. These links can be translated if multiple languages are used for the site.');
20 if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
21 $output .= ' ' . t('It is required by the Menu UI module, which provides an interface for managing menus and menu links. For more information, see the <a href=":menu-help">Menu UI module help page</a> and the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>.', [':menu-help' => \Drupal::url('help.page', ['name' => 'menu_ui']), ':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link']);
24 $output .= ' ' . t('For more information, see the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>. If you enable the Menu UI module, it provides an interface for managing menus and menu links.', [':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link']);
32 * Implements hook_menu_delete().
34 function menu_link_content_menu_delete(MenuInterface $menu) {
35 $storage = \Drupal::entityManager()->getStorage('menu_link_content');
36 $menu_links = $storage->loadByProperties(['menu_name' => $menu->id()]);
37 $storage->delete($menu_links);
41 * Implements hook_path_insert().
43 function menu_link_content_path_insert($path) {
44 _menu_link_content_update_path_alias($path['alias']);
48 * Helper function to update plugin definition using internal scheme.
53 function _menu_link_content_update_path_alias($path) {
54 /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
55 $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
56 /** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $entities */
57 $entities = \Drupal::entityManager()
58 ->getStorage('menu_link_content')
59 ->loadByProperties(['link.uri' => 'internal:' . $path]);
60 foreach ($entities as $menu_link) {
61 $menu_link_manager->updateDefinition($menu_link->getPluginId(), $menu_link->getPluginDefinition(), FALSE);
66 * Implements hook_path_update().
68 function menu_link_content_path_update($path) {
69 if ($path['alias'] != $path['original']['alias']) {
70 _menu_link_content_update_path_alias($path['alias']);
71 _menu_link_content_update_path_alias($path['original']['alias']);
73 elseif ($path['source'] != $path['original']['source']) {
74 _menu_link_content_update_path_alias($path['alias']);
79 * Implements hook_path_delete().
81 function menu_link_content_path_delete($path) {
82 _menu_link_content_update_path_alias($path['alias']);