You are here

public static function PriceList::postDelete in Commerce Pricelist 8

Same name and namespace in other branches
  1. 8.2 src/Entity/PriceList.php \Drupal\commerce_pricelist\Entity\PriceList::postDelete()

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/PriceList.php, line 216

Class

PriceList
Defines the Price list entity.

Namespace

Drupal\commerce_pricelist\Entity

Code

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

  // Delete the price list item of a deleted price list.
  $price_list_items = [];
  foreach ($entities as $entity) {
    if (empty($entity->field_price_list_item)) {
      continue;
    }
    foreach ($entity->field_price_list_item as $item) {
      $price_list_items[$item->target_id] = $item->entity;
    }
    $price_list_item_storage = \Drupal::service('entity_type.manager')
      ->getStorage('price_list_item');
    $price_list_item_storage
      ->delete($price_list_items);
  }
}