public function LingotekFake::uploadDocument in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 8 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 8.2 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 4.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.1.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.2.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.3.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.4.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.6.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.7.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
- 3.8.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::uploadDocument()
Uploads a document to the Lingotek service.
Parameters
string $title: The title of the document as it will be seen in the TMS.
string|array $content: The content of the document. It can be a json string or an array that will be json encoded.
string $locale: The Lingotek locale.
string $url: (optional) The document url in the site if any. This allows support for in-context review.
\Drupal\lingotek\LingotekProfileInterface $profile: (optional) The profile being used.
string $job_id: (optional) The job ID that will be associated.
Return value
string The document ID assigned to the uploaded document.
Throws
\Drupal\lingotek\Exception\LingotekPaymentRequiredException
\Drupal\lingotek\Exception\LingotekApiException
Overrides LingotekInterface::uploadDocument
File
- tests/
modules/ lingotek_test/ src/ LingotekFake.php, line 140
Class
Namespace
Drupal\lingotek_testCode
public function uploadDocument($title, $content, $locale, $url = NULL, LingotekProfileInterface $profile = NULL, $job_id = NULL) {
if (\Drupal::state()
->get('lingotek.must_error_in_upload', FALSE)) {
throw new LingotekApiException('Error was forced.');
}
if (\Drupal::state()
->get('lingotek.must_payment_required_error_in_upload', FALSE)) {
throw new LingotekPaymentRequiredException('Error was forced.');
}
if (is_array($content)) {
$content = json_encode($content);
}
// If the upload is successful, we must return a valid hash.
\Drupal::state()
->set('lingotek.uploaded_title', $title);
\Drupal::state()
->set('lingotek.uploaded_content', $content);
\Drupal::state()
->set('lingotek.uploaded_locale', $locale);
\Drupal::state()
->set('lingotek.uploaded_url', $url);
\Drupal::state()
->set('lingotek.uploaded_job_id', $job_id);
\Drupal::state()
->set('lingotek.used_profile', $profile ? $profile
->id() : NULL);
$count = \Drupal::state()
->get('lingotek.uploaded_docs', 0);
$doc_id = 'dummy-document-hash-id';
if ($count > 0) {
$doc_id .= '-' . $count;
}
++$count;
\Drupal::state()
->set('lingotek.last_used_id', $count);
\Drupal::state()
->set('lingotek.uploaded_docs', $count);
// Save the timestamp of the upload.
$timestamps = \Drupal::state()
->get('lingotek.upload_timestamps', []);
$timestamps[$doc_id] = \Drupal::time()
->getRequestTime();
\Drupal::state()
->set('lingotek.upload_timestamps', $timestamps);
return $doc_id;
}