You are here

public static function ProductBundle::postDelete in Commerce Product Bundle 8

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/ProductBundle.php, line 329

Class

ProductBundle
Defines the product bundle entity.

Namespace

Drupal\commerce_product_bundle\Entity

Code

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

  // Delete the product bundle items of a deleted product bundle.
  $bundleItems = [];

  /** @var \Drupal\commerce_product_bundle\Entity\BundleInterface $bundle */
  foreach ($entities as $entity) {
    if (empty($entity->bundle_items)) {
      continue;
    }
    foreach ($entity->bundle_items as $item) {
      $bundleItems[$item->target_id] = $item->entity;
    }
  }
  $storage = \Drupal::service('entity_type.manager')
    ->getStorage('commerce_product_bundle_i');
  $storage
    ->delete($bundleItems);
}