public function LingotekContentTranslationService::downloadDocument in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
- 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::downloadDocument()
Downloads a document from the Lingotek service for a given locale.
Parameters
\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity being downloaded.
string $locale: Lingotek translation language which we want to download.
Return value
boolean TRUE if the document was downloaded successfully, FALSE if not.
Overrides LingotekContentTranslationServiceInterface::downloadDocument
File
- src/
LingotekContentTranslationService.php, line 641 - Contains \Drupal\lingotek\LingotekContentTranslationService.
Class
- LingotekContentTranslationService
- Service for managing Lingotek content translations.
Namespace
Drupal\lingotekCode
public function downloadDocument(ContentEntityInterface &$entity, $locale) {
if ($document_id = $this
->getDocumentId($entity)) {
$source_status = $this
->getSourceStatus($entity);
try {
$data = $this->lingotek
->downloadDocument($document_id, $locale);
} catch (LingotekApiException $exception) {
// TODO: log issue
return FALSE;
}
if ($data) {
// Check the real status, because it may still need review or anything.
$status = $this->lingotek
->getDocumentTranslationStatus($document_id, $locale);
$transaction = db_transaction();
try {
$drupal_language = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale);
$langcode = $drupal_language
->id();
$saved = $this
->saveTargetData($entity, $langcode, $data);
if ($saved) {
// If the status was "Importing", and the target was added
// successfully, we can ensure that the content is current now.
if ($source_status == Lingotek::STATUS_IMPORTING || $source_status == Lingotek::STATUS_EDITED) {
$this
->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
}
if ($status) {
$this
->setTargetStatus($entity, $langcode, Lingotek::STATUS_CURRENT);
}
else {
$this
->setTargetStatus($entity, $langcode, Lingotek::STATUS_INTERMEDIATE);
}
}
} catch (LingotekContentEntityStorageException $storageException) {
throw $storageException;
} catch (\Exception $exception) {
$transaction
->rollback();
return FALSE;
}
return TRUE;
}
}
return FALSE;
}