You are here

function lingotek_entity_delete in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 8 lingotek.module \lingotek_entity_delete()
  2. 8.2 lingotek.module \lingotek_entity_delete()
  3. 7.3 lingotek.module \lingotek_entity_delete()
  4. 7.4 lingotek.module \lingotek_entity_delete()
  5. 7.5 lingotek.module \lingotek_entity_delete()
  6. 7.6 lingotek.module \lingotek_entity_delete()
  7. 4.0.x lingotek.module \lingotek_entity_delete()
  8. 3.0.x lingotek.module \lingotek_entity_delete()
  9. 3.1.x lingotek.module \lingotek_entity_delete()
  10. 3.2.x lingotek.module \lingotek_entity_delete()
  11. 3.3.x lingotek.module \lingotek_entity_delete()
  12. 3.4.x lingotek.module \lingotek_entity_delete()
  13. 3.5.x lingotek.module \lingotek_entity_delete()
  14. 3.7.x lingotek.module \lingotek_entity_delete()
  15. 3.8.x lingotek.module \lingotek_entity_delete()

Implements hook_entity_delete().

File

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

Code

function lingotek_entity_delete(EntityInterface $entity) {

  // Only act on content entities.
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  if (\Drupal::isConfigSyncing()) {

    // We don't want to react to configuration imports.
    return;
  }

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
  $translation_service = \Drupal::service('lingotek.content_translation');

  // Cancel the TMS document if it's been uploaded.
  if ($translation_service
    ->getDocumentId($entity)) {
    try {
      $response = $translation_service
        ->cancelDocument($entity);
    } catch (LingotekApiException $exception) {
      \Drupal::messenger()
        ->addError(t('Failed cancelling @entity_type %title. Please try again.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      ]));
    }
  }
}