You are here

function lingotek_entity_delete in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 lingotek.module \lingotek_entity_delete()
  2. 7.3 lingotek.module \lingotek_entity_delete()
  3. 7.4 lingotek.module \lingotek_entity_delete()
  4. 7.5 lingotek.module \lingotek_entity_delete()
  5. 7.6 lingotek.module \lingotek_entity_delete()
  6. 4.0.x lingotek.module \lingotek_entity_delete()
  7. 3.0.x lingotek.module \lingotek_entity_delete()
  8. 3.1.x lingotek.module \lingotek_entity_delete()
  9. 3.2.x lingotek.module \lingotek_entity_delete()
  10. 3.3.x lingotek.module \lingotek_entity_delete()
  11. 3.4.x lingotek.module \lingotek_entity_delete()
  12. 3.5.x lingotek.module \lingotek_entity_delete()
  13. 3.6.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 267
lingotek.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');

  // Delete the TMS document if it hasn't been disassociated
  if ($translation_service
    ->getDocumentId($entity)) {
    try {
      $response = $translation_service
        ->deleteDocument($entity);
    } catch (LingotekApiException $exception) {
      drupal_set_message(t('Failed deleting @entity_type %title. Please try again.', array(
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      )), 'error');
    }
  }
}