You are here

public static function PriceList::postDelete in Commerce Pricelist 8.2

Same name and namespace in other branches
  1. 8 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 284

Class

PriceList
Defines the Price list entity.

Namespace

Drupal\commerce_pricelist\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $entities) {
  $price_list_item_storage = \Drupal::entityTypeManager()
    ->getStorage('commerce_pricelist_item');
  $query = $price_list_item_storage
    ->getQuery();
  $query
    ->condition('price_list_id', EntityHelper::extractIds($entities), 'IN');
  $result = $query
    ->execute();
  if (!empty($result)) {

    // @todo This can crash due to there potentially being thousands of items.
    $price_list_items = $price_list_item_storage
      ->loadMultiple($result);
    $price_list_item_storage
      ->delete($price_list_items);
  }
}