You are here

public function Lingotek::cancelDocumentTarget in Lingotek Translation 3.4.x

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

Cancels the document target with this document id and locale from the Lingotek service.

Parameters

string $doc_id: The document id in Lingotek.

string $locale: The locale target we want to cancel the translation.

Return value

bool TRUE if the document target was successfully cancelled. FALSE if not.

Overrides LingotekInterface::cancelDocumentTarget

File

src/Lingotek.php, line 529

Class

Lingotek
The connecting class between Drupal and Lingotek

Namespace

Drupal\lingotek

Code

public function cancelDocumentTarget($doc_id, $locale) {
  $result = FALSE;
  try {
    $response = $this->api
      ->cancelDocumentTarget($doc_id, $locale);
    $status_code = $response
      ->getStatusCode();
    if ($status_code == Response::HTTP_NO_CONTENT) {
      $result = TRUE;
    }
  } catch (LingotekApiException $ltkException) {
    if ($ltkException
      ->getCode() === 400) {
      if (strpos($ltkException
        ->getMessage(), '"Unable to cancel translations which are already in a completed state. Current status: COMPLETE"') > 0) {

        // We ignore errors for complete documents.
        $result = TRUE;
      }
    }
  }
  return $result;
}