public function LingotekEntityController::update in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 8 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 4.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.2.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.3.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
- 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::update()
1 string reference to 'LingotekEntityController::update'
File
- src/
Controller/ LingotekEntityController.php, line 250
Class
Namespace
Drupal\lingotek\ControllerCode
public function update($doc_id) {
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $translation_service */
$translation_service = \Drupal::service('lingotek.content_translation');
$entity = $translation_service
->loadByDocumentId($doc_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);
}
try {
if ($translation_service
->updateDocument($entity)) {
$this
->messenger()
->addStatus(t('@entity_type %title has been updated.', [
'@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 (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addError(t('Document @entity_type %title has been archived. Please upload again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError(t('Document @entity_type %title has a new version. The document id has been updated for all future interactions. Please 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 update for @entity_type %title failed. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
return $this
->translationsPageRedirect($entity);
}