public function LingotekEntityController::upload in Lingotek Translation 3.2.x
Same name and namespace in other branches
- 8 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 4.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.3.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.5.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
- 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::upload()
1 string reference to 'LingotekEntityController::upload'
File
- src/
Controller/ LingotekEntityController.php, line 213
Class
Namespace
Drupal\lingotek\ControllerCode
public function upload($entity_type, $entity_id) {
$entity = $this
->entityTypeManager()
->getStorage($entity_type)
->load($entity_id);
if (!$entity) {
// TODO: log warning
return $this
->translationsPageRedirect($entity);
}
$bundleInfos = $this->entityTypeBundleInfo
->getBundleInfo($entity
->getEntityTypeId());
if (!$entity
->getEntityType()
->isTranslatable() || !$bundleInfos[$entity
->bundle()]['translatable']) {
\Drupal::messenger()
->addWarning(t('Cannot upload @type %label. That @bundle_label is not enabled for translation.', [
'@type' => $bundleInfos[$entity
->bundle()]['label'],
'%label' => $entity
->label(),
'@bundle_label' => $entity
->getEntityType()
->getBundleLabel(),
]));
return $this
->translationsPageRedirect($entity);
}
if (!$this->lingotekConfiguration
->isEnabled($entity
->getEntityTypeId(), $entity
->bundle())) {
$this
->messenger()
->addWarning(t('Cannot upload @type %label. That @bundle_label is not enabled for Lingotek translation.', [
'@type' => $bundleInfos[$entity
->bundle()]['label'],
'%label' => $entity
->label(),
'@bundle_label' => $entity
->getEntityType()
->getBundleLabel(),
]));
return $this
->translationsPageRedirect($entity);
}
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
try {
if ($translation_service
->uploadDocument($entity)) {
$this
->messenger()
->addStatus(t('@entity_type %title has been uploaded.', [
'@entity_type' => ucfirst($entity
->getEntityTypeId()),
'%title' => $entity
->label(),
]));
}
else {
$this
->messenger()
->addError(t('The upload for @entity_type %title failed. Check your configuration and profile and try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekApiException $exception) {
$this
->messenger()
->addError(t('The upload for @entity_type %title failed. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
return $this
->translationsPageRedirect($entity);
}