You are here

public function LingotekFake::cancelDocumentTarget in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 8.2 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  2. 3.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  3. 3.1.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  4. 3.2.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  5. 3.3.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  6. 3.4.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  7. 3.5.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  8. 3.6.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  9. 3.7.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::cancelDocumentTarget()
  10. 3.8.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::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.

Throws

\Drupal\lingotek\Exception\LingotekDocumentTargetAlreadyCompletedException If the target was already completed.

Overrides LingotekInterface::cancelDocumentTarget

File

tests/modules/lingotek_test/src/LingotekFake.php, line 394

Class

LingotekFake

Namespace

Drupal\lingotek_test

Code

public function cancelDocumentTarget($doc_id, $locale) {
  if (\Drupal::state()
    ->get('lingotek.must_error_in_cancel', FALSE)) {
    \Drupal::state()
      ->set('lingotek.must_error_in_cancel', FALSE);
    throw new LingotekApiException('Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.cancel_target_already_completed', FALSE)) {
    $msg = 'Error: "Unable to cancel translations which are already in a completed state. Current status: LATE"';
    throw new LingotekDocumentTargetAlreadyCompletedException($msg, 400);
  }
  if (\Drupal::state()
    ->get('lingotek.must_document_not_found_error_in_cancel', FALSE)) {
    throw new LingotekDocumentNotFoundException($doc_id . ' not found. Error was forced.');
  }
  $cancelled_locales = \Drupal::state()
    ->get('lingotek.cancelled_locales', []);
  $cancelled_locales[$doc_id][] = $locale;
  \Drupal::state()
    ->set('lingotek.cancelled_locales', $cancelled_locales);

  // Cancelled locale target.
  return TRUE;
}