menu_ui_node_predelete

menu_ui_node_predelete(EntityInterface $node)

Implements hook_ENTITY_TYPE_predelete() for node entities.

File

core/modules/menu_ui/menu_ui.module, line 169
Allows administrators to customize the site's navigation menus.

Code

function menu_ui_node_predelete(EntityInterface $node) {
  // Delete all MenuLinkContent links that point to this node.
  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  $result = $menu_link_manager->loadLinksByRoute('entity.node.canonical', array('node' => $node->id()));

  if (!empty($result)) {
    foreach ($result as $id => $instance) {
      if ($instance->isDeletable() && strpos($id, 'menu_link_content:') === 0) {
        $instance->deleteLink();
      }
    }
  }
}
doc_Drupal
2016-10-29 09:27:52
Comments
Leave a Comment

Please login to continue.