You are here

public static function JobItem::postDelete in Translation Management Tool 8

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/JobItem.php, line 215

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public static function postDelete(EntityStorageInterface $storage, array $entities) {
  parent::postDelete($storage, $entities);
  $entity_type_manager = \Drupal::entityTypeManager();

  // Since we are deleting one or multiple job items here we also need to
  // delete the attached messages.
  $mids = \Drupal::entityQuery('tmgmt_message')
    ->condition('tjiid', array_keys($entities), 'IN')
    ->execute();
  if (!empty($mids)) {
    $messages = $entity_type_manager
      ->getStorage('tmgmt_message')
      ->loadMultiple($mids);
    $entity_type_manager
      ->getStorage('tmgmt_message')
      ->delete($messages);
  }
  $trids = \Drupal::entityQuery('tmgmt_remote')
    ->condition('tjiid', array_keys($entities), 'IN')
    ->execute();
  if (!empty($trids)) {
    $remotes = $entity_type_manager
      ->getStorage('tmgmt_remote')
      ->loadMultiple($trids);
    $entity_type_manager
      ->getStorage('tmgmt_remote')
      ->delete($remotes);
  }
}