public static function Invoice::postDelete in Commerce Invoice 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 EntityBase::postDelete
File
- src/
Entity/ Invoice.php, line 663
Class
- Invoice
- Defines the invoice entity class.
Namespace
Drupal\commerce_invoice\EntityCode
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
// Delete the invoice items of a deleted invoice.
$invoice_items = [];
/** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $entity */
foreach ($entities as $entity) {
foreach ($entity
->getItems() as $invoice_item) {
$invoice_items[$invoice_item
->id()] = $invoice_item;
}
}
if (!$invoice_items) {
return;
}
$invoice_item_storage = \Drupal::service('entity_type.manager')
->getStorage('commerce_invoice_item');
$invoice_item_storage
->delete($invoice_items);
}