You are here

public static function Wishlist::postDelete in Commerce Wishlist 8.3

Acts on deleted entities before the delete hook is invoked.

Used after the entities are deleted but before invoking the delete hook.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.

Overrides EntityBase::postDelete

File

src/Entity/Wishlist.php, line 372

Class

Wishlist
Defines the wishlist entity class.

Namespace

Drupal\commerce_wishlist\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $entities) {
  parent::postDelete($storage, $entities);

  // Delete the wishlist items of a deleted wishlist.
  $wishlist_items = [];

  /** @var \Drupal\commerce_wishlist\Entity\WishlistInterface $entity */
  foreach ($entities as $entity) {
    foreach ($entity
      ->getItems() as $wishlist_item) {
      $wishlist_items[$wishlist_item
        ->id()] = $wishlist_item;
    }
  }

  /** @var \Drupal\commerce_wishlist\WishlistItemStorageInterface $wishlist_item_storage */
  $wishlist_item_storage = \Drupal::service('entity_type.manager')
    ->getStorage('commerce_wishlist_item');
  $wishlist_item_storage
    ->delete($wishlist_items);
}