You are here

public function MenuLinkManager::removeDefinition in Drupal 8

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

Removes a single link definition from the menu tree storage.

This is used for plugins not found through discovery to remove definitions.

Parameters

string $id: The menu link plugin ID.

bool $persist: If TRUE, this method will attempt to persist the deletion from any external storage by invoking MenuLinkInterface::deleteLink() on the plugin that is being deleted.

Throws

\Drupal\Component\Plugin\Exception\PluginException Thrown if the $id is not a valid, existing, plugin ID or if the link cannot be deleted.

Overrides MenuLinkManagerInterface::removeDefinition

File

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

Class

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

Namespace

Drupal\Core\Menu

Code

public function removeDefinition($id, $persist = TRUE) {
  $definition = $this->treeStorage
    ->load($id);

  // It's possible the definition has already been deleted, or doesn't exist.
  if ($definition) {
    $instance = $this
      ->createInstance($id);
    $this
      ->deleteInstance($instance, $persist);
  }
}