You are here

public function LingotekContentTranslationService::cancelDocument in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  2. 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  3. 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  4. 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  5. 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  6. 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  7. 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  8. 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  9. 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()
  10. 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocument()

Cancels a document from the server.

Parameters

\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity which we want to cancel.

Return value

\Drupal\Core\Entity\ContentEntityInterface The entity.

Throws

\Drupal\lingotek\Exception\LingotekDocumentNotFoundException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekContentTranslationServiceInterface::cancelDocument

1 call to LingotekContentTranslationService::cancelDocument()
LingotekContentTranslationService::deleteMetadata in src/LingotekContentTranslationService.php
Deletes all local metadata related to an entity.

File

src/LingotekContentTranslationService.php, line 1575

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function cancelDocument(ContentEntityInterface &$entity) {
  $result = FALSE;
  $doc_id = $this
    ->getDocumentId($entity);
  if ($doc_id) {
    try {
      $result = $this->lingotek
        ->cancelDocument($doc_id);
      $this->lingotekConfiguration
        ->setProfile($entity, NULL);
      $this
        ->setDocumentId($entity, NULL);
    } catch (LingotekDocumentAlreadyCompletedException $exception) {
      \Drupal::logger('lingotek')
        ->warning('The document %label (%doc_id) was not cancelled on the TMS side as it was already completed.', [
        '%label' => $entity
          ->label(),
        '%doc_id' => $doc_id,
      ]);
      $this->lingotekConfiguration
        ->setProfile($entity, NULL);
      $this
        ->setDocumentId($entity, NULL);
    } catch (LingotekDocumentNotFoundException $exception) {
      $this
        ->setDocumentId($entity, NULL);
      $this
        ->deleteMetadata($entity);
      throw $exception;
    }
  }
  $this
    ->setSourceStatus($entity, Lingotek::STATUS_CANCELLED);
  $this
    ->setTargetStatuses($entity, Lingotek::STATUS_CANCELLED);
  return $result;
}