You are here

public function LingotekEntityController::checkTarget in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  2. 4.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  3. 3.0.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  4. 3.1.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  5. 3.2.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  6. 3.3.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  7. 3.4.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  8. 3.5.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  9. 3.6.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  10. 3.7.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
  11. 3.8.x src/Controller/LingotekEntityController.php \Drupal\lingotek\Controller\LingotekEntityController::checkTarget()
1 string reference to 'LingotekEntityController::checkTarget'
lingotek.routing.yml in ./lingotek.routing.yml
lingotek.routing.yml

File

src/Controller/LingotekEntityController.php, line 39

Class

LingotekEntityController

Namespace

Drupal\lingotek\Controller

Code

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);
  }
  $drupal_language = $this->languageLocaleMapper
    ->getConfigurableLanguageForLocale($locale);
  try {
    if ($translation_service
      ->checkTargetStatus($entity, $drupal_language
      ->id()) === Lingotek::STATUS_READY) {
      drupal_set_message(t('The @locale translation for @entity_type %title is ready for download.', array(
        '@locale' => $locale,
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      )));
    }
    else {
      drupal_set_message(t('The @locale translation for @entity_type %title is still in progress.', array(
        '@locale' => $locale,
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      )));
    }
  } catch (LingotekApiException $exc) {
    drupal_set_message(t('The request for @entity_type translation status failed. Please try again.', array(
      '@entity_type' => $entity
        ->getEntityTypeId(),
      '%title' => $entity
        ->label(),
    )), 'error');
  }
  return $this
    ->translationsPageRedirect($entity);
}