You are here

public function MenuLinkManager::deleteLinksInMenu in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::deleteLinksInMenu()

Deletes all links having a certain menu name.

If a link is not deletable but is resettable, the link will be reset to have its original menu name, under the assumption that the original menu is not the one we are deleting it from. Note that when resetting, if the original menu name is the same as the menu name passed to this method, the link will not be moved or deleted.

Parameters

string $menu_name: The name of the menu whose links will be deleted or reset.

Overrides MenuLinkManagerInterface::deleteLinksInMenu

File

core/lib/Drupal/Core/Menu/MenuLinkManager.php, line 248

Class

MenuLinkManager
Manages discovery, instantiation, and tree building of menu link plugins.

Namespace

Drupal\Core\Menu

Code

public function deleteLinksInMenu($menu_name) {
  foreach ($this->treeStorage
    ->loadByProperties([
    'menu_name' => $menu_name,
  ]) as $plugin_id => $definition) {
    $instance = $this
      ->createInstance($plugin_id);
    if ($instance
      ->isDeletable()) {
      $this
        ->deleteInstance($instance, TRUE);
    }
    elseif ($instance
      ->isResettable()) {
      $new_instance = $this
        ->resetInstance($instance);
      $affected_menus[$new_instance
        ->getMenuName()] = $new_instance
        ->getMenuName();
    }
  }
}