public static function Translator::preDelete

File

src/Entity/Translator.php, line 248

Class

Translator
Entity class for the tmgmt_translator entity.

Namespace

Drupal\tmgmt\Entity

Code

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

  // We are never going to have many entities here, so we can risk a loop.
  foreach ($entities as $key => $name) {

    // Find active jobs associated with the translator that is being deleted.
    $job_ids = \Drupal::entityQuery('tmgmt_job')
      ->accessCheck(TRUE)
      ->condition('state', [
      Job::STATE_ACTIVE,
      Job::STATE_CONTINUOUS,
      Job::STATE_UNPROCESSED,
    ], 'IN')
      ->condition('translator', $key)
      ->execute();
    $jobs = Job::loadMultiple($job_ids);

    /** @var \Drupal\tmgmt\JobInterface $job */
    foreach ($jobs as $job) {
      $job
        ->aborted('Job has been aborted because the translation provider %provider was deleted.', [
        '%provider' => $job
          ->getTranslatorLabel(),
      ]);
    }
  }
  parent::preDelete($storage, $entities);
}