public function LingotekContentTranslationService::setJobId in Lingotek Translation 3.3.x
Same name and namespace in other branches
- 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
- 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::setJobId()
Sets the job ID of a given entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity we want to save a job id for.
string $job_id: The job ID being saved.
bool $update_tms: (Optional) Flag indicating if the change should be communicated to the TMS. False by default.
Return value
\Drupal\Core\Entity\ContentEntityInterface Returns the entity which job ID is saved.
Throws
\Drupal\lingotek\Exception\LingotekPaymentRequiredException
\Drupal\lingotek\Exception\LingotekDocumentArchivedException
\Drupal\lingotek\Exception\LingotekDocumentLockedException
\Drupal\lingotek\Exception\LingotekApiException
Overrides LingotekContentTranslationServiceInterface::setJobId
2 calls to LingotekContentTranslationService::setJobId()
- LingotekContentTranslationService::updateDocument in src/
LingotekContentTranslationService.php - Resends a document to the translation service.
- LingotekContentTranslationService::uploadDocument in src/
LingotekContentTranslationService.php - Uploads a document to the Lingotek service.
File
- src/
LingotekContentTranslationService.php, line 1777
Class
- LingotekContentTranslationService
- Service for managing Lingotek content translations.
Namespace
Drupal\lingotekCode
public function setJobId(ContentEntityInterface $entity, $job_id, $update_tms = FALSE) {
if (!$entity->lingotek_metadata->entity) {
$entity->lingotek_metadata->entity = LingotekContentMetadata::loadByTargetId($entity
->getEntityTypeId(), $entity
->id());
}
/** @var \Drupal\lingotek\Entity\LingotekContentMetadata $metadata */
$metadata =& $entity->lingotek_metadata->entity;
$newDocumentID = FALSE;
if ($update_tms && ($document_id = $this
->getDocumentId($entity))) {
try {
$newDocumentID = $this->lingotek
->updateDocument($document_id, NULL, NULL, NULL, NULL, $job_id);
} catch (LingotekDocumentLockedException $exception) {
$this
->setDocumentId($entity, $exception
->getNewDocumentId());
throw $exception;
} catch (LingotekDocumentArchivedException $exception) {
$old_job_id = $this
->getJobId($entity);
$this
->setDocumentId($entity, NULL);
$this
->deleteMetadata($entity);
$metadata = LingotekContentMetadata::create([
'content_entity_type_id' => $entity
->getEntityTypeId(),
'content_entity_id' => $entity
->id(),
]);
$metadata
->setJobId($old_job_id);
$metadata
->save();
throw $exception;
} catch (LingotekPaymentRequiredException $exception) {
throw $exception;
} catch (LingotekApiException $exception) {
throw $exception;
}
}
if (is_string($newDocumentID)) {
$metadata
->setDocumentId($newDocumentID);
}
$metadata
->setJobId($job_id);
$metadata
->save();
return $entity;
}