public function LingotekContentTranslationService::updateDocument in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
- 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::updateDocument()
Resends a document to the translation service.
Parameters
\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity being updated.
string $job_id: (optional) The job ID that will be associated.
Return value
bool TRUE if the document was updated successfully, FALSE if not.
Throws
\Drupal\lingotek\Exception\LingotekPaymentRequiredException
\Drupal\lingotek\Exception\LingotekDocumentArchivedException
\Drupal\lingotek\Exception\LingotekDocumentLockedException
\Drupal\lingotek\Exception\LingotekDocumentNotFoundException
\Drupal\lingotek\Exception\LingotekApiException
Overrides LingotekContentTranslationServiceInterface::updateDocument
1 call to LingotekContentTranslationService::updateDocument()
- LingotekContentTranslationService::uploadDocument in src/
LingotekContentTranslationService.php - Uploads a document to the Lingotek service.
File
- src/
LingotekContentTranslationService.php, line 1408
Class
- LingotekContentTranslationService
- Service for managing Lingotek content translations.
Namespace
Drupal\lingotekCode
public function updateDocument(ContentEntityInterface &$entity, $job_id = NULL) {
$profile = $this->lingotekConfiguration
->getEntityProfile($entity);
if ($profile
->id() === Lingotek::PROFILE_DISABLED || $this
->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED) {
return FALSE;
}
// If job id was not set in the form, it may be already assigned.
if ($job_id === NULL) {
$job_id = $this
->getJobId($entity) ?: NULL;
}
$source_data = $this
->getSourceData($entity);
$document_id = $this
->getDocumentId($entity);
$source_langcode = $entity
->getUntranslated()
->language()
->getId();
$source_locale = $this->languageLocaleMapper
->getLocaleForLangcode($source_langcode);
$url = $entity
->hasLinkTemplate('canonical') ? $entity
->toUrl()
->setAbsolute(TRUE)
->toString() : NULL;
$extended_name = $entity
->bundle() . ' (' . $entity
->getEntityTypeId() . '): ' . $entity
->label();
$profile_preference = $profile
->getAppendContentTypeToTitle();
$global_preference = $this->lingotekConfiguration
->getPreference('append_type_to_title');
switch ($profile_preference) {
case 'yes':
$document_name = $extended_name;
break;
case 'no':
$document_name = $entity
->label();
break;
case 'global_setting':
$document_name = $global_preference ? $extended_name : $entity
->label();
break;
default:
$document_name = $extended_name;
}
// Allow other modules to alter the data before is uploaded.
\Drupal::moduleHandler()
->invokeAll('lingotek_content_entity_document_upload', [
&$source_data,
&$entity,
&$url,
]);
$process_id = NULL;
try {
$newDocumentID = $this->lingotek
->updateDocument($document_id, $source_data, $url, $document_name, $profile, $job_id, $source_locale, $process_id);
} catch (LingotekDocumentNotFoundException $exception) {
$this
->setDocumentId($entity, NULL);
$this
->deleteMetadata($entity);
throw $exception;
} catch (LingotekDocumentLockedException $exception) {
$this
->setDocumentId($entity, $exception
->getNewDocumentId());
throw $exception;
} catch (LingotekDocumentArchivedException $exception) {
$this
->setDocumentId($entity, NULL);
$this
->setSourceStatus($entity, Lingotek::STATUS_ARCHIVED);
$this
->setTargetStatuses($entity, Lingotek::STATUS_ARCHIVED);
throw $exception;
} catch (LingotekPaymentRequiredException $exception) {
$this
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
throw $exception;
} catch (LingotekApiException $exception) {
$this
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
throw $exception;
}
if ($newDocumentID) {
if (is_string($newDocumentID)) {
$document_id = $newDocumentID;
$this
->setDocumentId($entity, $newDocumentID);
}
$this
->setSourceStatus($entity, Lingotek::STATUS_IMPORTING);
$this
->setTargetStatuses($entity, Lingotek::STATUS_PENDING);
$this
->setJobId($entity, $job_id);
$this
->setLastUpdated($entity, \Drupal::time()
->getRequestTime());
if ($process_id !== NULL) {
$this
->storeUploadProcessId($entity, $process_id);
}
return $newDocumentID;
}
if ($this
->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
$this
->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
}
return FALSE;
}