public function MenuLinkManager::deleteLinksInMenu

public MenuLinkManager::deleteLinksInMenu($menu_name)

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 250

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(array('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();
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Menu!MenuLinkManager.php/function/MenuLinkManager::deleteLinksInMenu/8.1.x