You are here

public static function Translator::preDelete in Translation Management Tool 8

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and 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 ConfigEntityBase::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')
      ->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);
}