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();
    }
  }
}
doc_Drupal
2016-10-29 09:27:05
Comments
Leave a Comment

Please login to continue.