You are here

public function LingotekFake::addTarget in Lingotek Translation 3.5.x

Same name and namespace in other branches
  1. 8 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  2. 8.2 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  3. 4.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  4. 3.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  5. 3.1.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  6. 3.2.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  7. 3.3.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  8. 3.4.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  9. 3.6.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  10. 3.7.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()
  11. 3.8.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::addTarget()

Requests a translation to the Lingotek service.

Parameters

string $doc_id: The document id to translate.

string $locale: The Lingotek locale to request.

\Drupal\lingotek\LingotekProfileInterface $profile: The profile being used.

Return value

bool TRUE if the document was successfully updated. FALSE if not.

Throws

\Drupal\lingotek\Exception\LingotekPaymentRequiredException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekInterface::addTarget

File

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

Class

LingotekFake

Namespace

Drupal\lingotek_test

Code

public function addTarget($doc_id, $locale, LingotekProfileInterface $profile = NULL) {
  if (\Drupal::state()
    ->get('lingotek.must_error_in_request_translation', FALSE)) {
    throw new LingotekApiException('Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_payment_required_error_in_request_translation', FALSE)) {
    throw new LingotekPaymentRequiredException('Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_document_archived_error_in_request_translation', FALSE)) {
    throw new LingotekDocumentArchivedException($doc_id, 'Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_document_locked_error_in_request_translation', FALSE)) {
    throw new LingotekDocumentLockedException($doc_id, 'new-doc-id', 'Error was forced.');
  }
  $requested_locales = \Drupal::state()
    ->get('lingotek.requested_locales', []);
  $requested_locales[$doc_id][] = $locale;
  \Drupal::state()
    ->set('lingotek.requested_locales', $requested_locales);
  \Drupal::state()
    ->set('lingotek.added_target_locale', $locale);
  \Drupal::state()
    ->set('lingotek.used_profile', $profile ? $profile
    ->id() : NULL);

  // Added locale as target.
  return TRUE;
}