You are here

public function MenuLinkContentStorage::delete in Multiversion 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Storage/Sql/MenuLinkContentStorage.php \Drupal\multiversion\Entity\Storage\Sql\MenuLinkContentStorage::delete()

Deletes permanently saved entities.

Parameters

array $entities: An array of entity objects to delete.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.

Overrides ContentEntityStorageTrait::delete

File

src/Entity/Storage/Sql/MenuLinkContentStorage.php, line 15

Class

MenuLinkContentStorage
Storage handler for menu link content.

Namespace

Drupal\multiversion\Entity\Storage\Sql

Code

public function delete(array $entities) {
  parent::delete($entities);

  // Remove the deleted entity as parent for all children.
  foreach ($entities as $entity) {
    $children = $this
      ->loadByProperties([
      'parent' => $entity
        ->getPluginId(),
    ]);
    foreach ($children as $child) {
      $child->parent->value = '';
      $child
        ->save();
    }
  }

  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  foreach ($entities as $menu_link) {

    // Remove link definition from the menu tree storage.
    $menu_link_manager
      ->removeDefinition($menu_link
      ->getPluginId(), FALSE);
  }
}