You are here

public function LingotekConfigTranslationController::request in Lingotek Translation 3.4.x

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

File

src/Controller/LingotekConfigTranslationController.php, line 410

Class

LingotekConfigTranslationController

Namespace

Drupal\lingotek\Controller

Code

public function request($entity_type, $entity_id, $locale, Request $request) {
  if ($entity_type === $entity_id) {

    // It is not a config entity, but a config object.
    $definition = $this->configMapperManager
      ->getDefinition($entity_type);
    try {
      if ($this->translationService
        ->addConfigTarget($entity_id, $locale)) {
        $this
          ->messenger()
          ->addStatus($this
          ->t('Translation to %locale requested successfully', [
          '%locale' => $locale,
        ]));
      }
    } catch (LingotekDocumentArchivedException $exception) {
      $this
        ->messenger()
        ->addError($this
        ->t('Document %label has been archived. Please upload again.', [
        '%label' => $definition['title'],
      ]));
    } catch (LingotekDocumentLockedException $exception) {
      $this
        ->messenger()
        ->addError($this
        ->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
        '%label' => $definition['title'],
      ]));
    } catch (LingotekPaymentRequiredException $exception) {
      $this
        ->messenger()
        ->addError($this
        ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
    } catch (LingotekApiException $e) {
      $this
        ->messenger()
        ->addError($this
        ->t('%label @locale translation request failed. Please try again.', [
        '%label' => $definition['title'],
        '@locale' => $locale,
      ]));
    }
    return $this
      ->redirectToConfigTranslateOverview($entity_type);
  }

  // Check if it's a field.
  if (substr($entity_type, -7) == '_fields') {

    // Hack for fields, the entity is field config.
    $entity_type = 'field_config';
  }
  $entity = $this
    ->entityTypeManager()
    ->getStorage($entity_type)
    ->load($entity_id);
  try {
    if ($this->translationService
      ->addTarget($entity, $locale)) {
      $this
        ->messenger()
        ->addStatus($this
        ->t('Translation to %locale requested successfully', [
        '%locale' => $locale,
      ]));
    }
  } catch (LingotekDocumentArchivedException $exception) {
    $this
      ->messenger()
      ->addError($this
      ->t('Document @entity_type %title has been archived. Please upload again.', [
      '@entity_type' => $entity
        ->getEntityTypeId(),
      '%title' => $entity
        ->label(),
    ]));
  } catch (LingotekDocumentLockedException $exception) {
    $this
      ->messenger()
      ->addError($this
      ->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($this
      ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
  } catch (LingotekApiException $e) {
    $this
      ->messenger()
      ->addError($this
      ->t('%label @locale translation request failed. Please try again.', [
      '%label' => $entity
        ->label(),
      '@locale' => $locale,
    ]));
  }
  return $this
    ->redirectToEntityTranslateOverview($entity_type, $entity_id);
}