You are here

protected function MenuLinkManager::deleteInstance in Drupal 9

Same name and namespace in other branches
  1. 8 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);
}