You are here

function lingotek_entity_translation_delete in Lingotek Translation 8.2

Same name and namespace in other branches
  1. 4.0.x lingotek.module \lingotek_entity_translation_delete()
  2. 3.0.x lingotek.module \lingotek_entity_translation_delete()
  3. 3.1.x lingotek.module \lingotek_entity_translation_delete()
  4. 3.2.x lingotek.module \lingotek_entity_translation_delete()
  5. 3.3.x lingotek.module \lingotek_entity_translation_delete()
  6. 3.4.x lingotek.module \lingotek_entity_translation_delete()
  7. 3.5.x lingotek.module \lingotek_entity_translation_delete()
  8. 3.6.x lingotek.module \lingotek_entity_translation_delete()
  9. 3.7.x lingotek.module \lingotek_entity_translation_delete()
  10. 3.8.x lingotek.module \lingotek_entity_translation_delete()

File

./lingotek.module, line 631
Implements Drupal-related hooks for the Lingotek Translation module.

Code

function lingotek_entity_translation_delete(ContentEntityInterface $entity) {

  /** @var \Drupal\lingotek\LanguageLocaleMapperInterface $languageMapper */
  $languageMapper = \Drupal::service('lingotek.language_locale_mapper');

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
  $lingotek_config = \Drupal::service('lingotek.configuration');

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');
  $langcode = $entity
    ->language()
    ->getId();
  if ($lingotek_config
    ->isEnabled($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {
    $document_id = $translation_service
      ->getDocumentId($entity);
    $translation_statuses = \Drupal::service('lingotek')
      ->getDocumentTranslationStatuses($document_id);
    foreach ($translation_statuses as $lingotek_locale => $progress) {
      $drupal_language = $languageMapper
        ->getConfigurableLanguageForLocale($lingotek_locale);
      if ($drupal_language
        ->getId() === $langcode) {
        if ($progress === Lingotek::PROGRESS_COMPLETE) {
          $translation_service
            ->setTargetStatus($entity, $langcode, Lingotek::STATUS_READY);
        }
        else {
          $translation_service
            ->setTargetStatus($entity, $langcode, Lingotek::STATUS_PENDING);
        }
        if (isset($entity->original)) {
          $entity->original->lingotek_processed = TRUE;
        }
        return;
      }
    }
  }
}