function MenuLinkManager::deleteInstance

Same name in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::deleteInstance()
  2. 10 core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::deleteInstance()
  3. 11.x core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::deleteInstance()

Deletes a specific instance.

Parameters

\Drupal\Core\Menu\MenuLinkInterface $instance: The plugin instance to be deleted.

bool $persist: If TRUE, calls MenuLinkInterface::deleteLink() on the instance.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the plugin instance does not support deletion.

2 calls to MenuLinkManager::deleteInstance()
MenuLinkManager::deleteLinksInMenu in core/lib/Drupal/Core/Menu/MenuLinkManager.php
Deletes all links having a certain menu name.
MenuLinkManager::removeDefinition in core/lib/Drupal/Core/Menu/MenuLinkManager.php
Removes a single link definition from the menu tree storage.

File

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

Class

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

Namespace

Drupal\Core\Menu

Code

protected function deleteInstance(MenuLinkInterface $instance, $persist) {
    $id = $instance->getPluginId();
    if ($instance->isDeletable()) {
        if ($persist) {
            $instance->deleteLink();
        }
    }
    else {
        throw new PluginException("Menu link plugin with ID '{$id}' does not support deletion");
    }
    $this->treeStorage
        ->delete($id);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.