You are here

public static function ProductAttribute::postDelete in Commerce Core 8.2

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 ConfigEntityBundleBase::postDelete

File

modules/product/src/Entity/ProductAttribute.php, line 108

Class

ProductAttribute
Defines the product attribute entity class.

Namespace

Drupal\commerce_product\Entity

Code

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

  /** @var \Drupal\commerce_product\Entity\ProductAttributeInterface[] $entities */
  parent::postDelete($storage, $entities);

  // Delete all associated values.
  $values = [];
  foreach ($entities as $entity) {
    foreach ($entity
      ->getValues() as $value) {
      $values[$value
        ->id()] = $value;
    }
  }

  /** @var \Drupal\Core\Entity\EntityStorageInterface $value_storage */
  $value_storage = \Drupal::service('entity_type.manager')
    ->getStorage('commerce_product_attribute_value');
  $value_storage
    ->delete($values);
}