You are here

public static function SmsMessage::postDelete in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::postDelete()
  2. 2.1.x src/Entity/SmsMessage.php \Drupal\sms\Entity\SmsMessage::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/SmsMessage.php, line 615

Class

SmsMessage
Defines the SMS message entity.

Namespace

Drupal\sms\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $entities) {
  parent::postDelete($storage, $entities);
  $results = [];
  $reports = [];

  /** @var \Drupal\sms\Entity\SmsMessageInterface $sms_message */
  foreach ($entities as $sms_message) {

    // Since the $sms_message can have both in-memory and stored objects, only
    // need to delete actual stored entities.
    if (($result = $sms_message
      ->getResult()) && $result instanceof EntityInterface) {
      $results[] = $result;
    }
    foreach ($sms_message
      ->getReports() as $report) {
      if ($report instanceof EntityInterface) {
        $reports[] = $report;
      }
    }
  }
  \Drupal::entityTypeManager()
    ->getStorage('sms_result')
    ->delete($results);
  \Drupal::entityTypeManager()
    ->getStorage('sms_report')
    ->delete($reports);
}