public function LingotekEntityController::addTarget in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 4.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.2.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.3.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.5.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
- 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::addTarget()
1 string reference to 'LingotekEntityController::addTarget'
File
- src/
Controller/ LingotekEntityController.php, line 63
Class
Namespace
Drupal\lingotek\ControllerCode
public function addTarget($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);
}
try {
if ($translation_service
->addTarget($entity, $locale)) {
drupal_set_message(t("Locale '@locale' was added as a translation target for @entity_type %title.", array(
'@locale' => $locale,
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)));
}
else {
drupal_set_message(t("There was a problem adding '@locale' as a translation target for @entity_type %title.", array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
'@locale' => $locale,
)), 'warning');
}
} catch (LingotekApiException $exception) {
drupal_set_message(t('The translation request for @entity_type failed. Please try again.', array(
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
)), 'error');
}
return $this
->translationsPageRedirect($entity);
}