You are here

public function MenuLinkField::deleteLink in Menu Link (Field) 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Menu/MenuLinkField.php \Drupal\menu_link\Plugin\Menu\MenuLinkField::deleteLink()

Deletes a menu link.

In general, this method should not be called directly, but will be called automatically from MenuLinkManagerInterface::removeDefinition().

This method will only delete the link from any additional storage, but not from the plugin.manager.menu.link service.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the link is not deletable.

Overrides MenuLinkBase::deleteLink

File

src/Plugin/Menu/MenuLinkField.php, line 203

Class

MenuLinkField
Provides a menu link plugin for field-based menu links.

Namespace

Drupal\menu_link\Plugin\Menu

Code

public function deleteLink() {
  $entity = $this
    ->getEntity();
  $field_name = $this
    ->getFieldName();
  $field_item_list = $entity
    ->get($field_name);
  $field_item_list->title = '';
  $field_item_list->description = '';
  $field_item_list->menu_name = '';
  $field_item_list->parent = '';
  $this->entity
    ->save();
}