public function LingotekEntityController::checkTarget in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 8 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.2.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.3.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.5.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
- 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
1 string reference to 'LingotekEntityController::checkTarget'
File
- src/
Controller/ LingotekEntityController.php, line 132
Class
Namespace
Drupal\lingotek\ControllerCode
public function checkTarget($doc_id, $locale) {
/** @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 check target for @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 check target for @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);
}
$drupal_language = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale);
try {
if ($translation_service
->checkTargetStatus($entity, $drupal_language
->id()) === Lingotek::STATUS_READY) {
$this
->messenger()
->addStatus(t('The @locale translation for @entity_type %title is ready for download.', [
'@locale' => $locale,
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
else {
$this
->messenger()
->addStatus(t('The @locale translation for @entity_type %title is still in progress.', [
'@locale' => $locale,
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
} catch (LingotekDocumentNotFoundException $exc) {
$this
->messenger()
->addError(t('Document @entity_type %title was not found. Please upload again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekApiException $exc) {
$this
->messenger()
->addError(t('The request for @entity_type translation status failed. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
return $this
->translationsPageRedirect($entity);
}