function lingotek_operation_content_upload in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 lingotek.batch.inc \lingotek_operation_content_upload()
- 4.0.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.0.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.1.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.2.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.3.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.4.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.5.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.6.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.7.x lingotek.batch.inc \lingotek_operation_content_upload()
- 3.8.x lingotek.batch.inc \lingotek_operation_content_upload()
Wrapper function for running content uploads.
1 string reference to 'lingotek_operation_content_upload'
- LingotekBatchController::getUploadOperations in src/
Controller/ LingotekBatchController.php
File
- ./
lingotek.batch.inc, line 14 - Lingotek batch functions
Code
function lingotek_operation_content_upload($entity_type, $entity_id, &$context) {
if ($context) {
$context['message'] = t('Uploading @entity_type @entity_id', array(
'@entity_type' => $entity_type,
'@entity_id' => $entity_id,
));
}
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
// Prepare the entity's translatable content for upload.
$entity = entity_load($entity_type, $entity_id);
// Use upload with new entities.
if (!$translation_service
->getDocumentId($entity)) {
$document_id = NULL;
try {
$document_id = $translation_service
->uploadDocument($entity);
} catch (LingotekApiException $exception) {
// Mark the document as failed.
$translation_service
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
}
if ($document_id) {
$context['results']['uploads'] = !empty($context['results']['uploads']) ? $context['results']['uploads'] + 1 : 1;
}
else {
// Mark the document as failed.
$translation_service
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
$context['results']['error'][] = t('The upload for @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
));
}
}
else {
try {
if ($translation_service
->updateDocument($entity)) {
$context['results']['uploads'] = !empty($context['results']['uploads']) ? $context['results']['uploads'] + 1 : 1;
}
else {
// ToDo: Log a problem happened updating the document.
}
} catch (LingotekApiException $exception) {
// Mark the document as failed.
$translation_service
->setSourceStatus($entity, Lingotek::STATUS_ERROR);
$context['results']['error'][] = t('The update for @entity_type %title failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
));
}
}
}