menu_link_content.module 1.39 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Allows administrators to create custom menu links.
 */

8
use Drupal\Core\Routing\RouteMatchInterface;
9 10
use Drupal\system\MenuInterface;

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * Implements hook_help().
 */
function menu_link_content_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.menu_link_content':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $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.');
      if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
        $output .= ' ' . t('It is required by the Menu UI module, which provides an interface for managing menus and menu links. See the <a href="!menu-help">Menu UI module help page</a> for more information.', array('!menu-help' => \Drupal::url('help.page', array('name' => 'menu_ui'))));
      }
      else {
        $output .= ' ' . t('If you enable the Menu UI module, it provides an interface for managing menus and menu links.');
      }
      $output .= '</p>';
      return $output;
  }
}

31 32 33 34 35 36 37 38
/**
 * Implements hook_menu_delete().
 */
function menu_link_content_menu_delete(MenuInterface $menu) {
  $storage = \Drupal::entityManager()->getStorage('menu_link_content');
  $menu_links = $storage->loadByProperties(array('menu_name' => $menu->id()));
  $storage->delete($menu_links);
}