You are here

public function LingotekManagementFormBase::requestTranslations in Lingotek Translation 3.1.x

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  2. 4.0.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  3. 3.0.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  4. 3.2.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  5. 3.3.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  6. 3.4.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  7. 3.5.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  8. 3.6.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  9. 3.7.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()
  10. 3.8.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::requestTranslations()

Request all translations for a given content.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

File

src/Form/LingotekManagementFormBase.php, line 1110

Class

LingotekManagementFormBase
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

public function requestTranslations(ContentEntityInterface $entity, $language, $job_id, &$context) {
  $result = NULL;
  $context['message'] = $this
    ->t('Requesting translations for @type %label.', [
    '@type' => $entity
      ->getEntityType()
      ->getLabel(),
    '%label' => $entity
      ->label(),
  ]);
  if ($profile = $this->lingotekConfiguration
    ->getEntityProfile($entity, FALSE)) {
    try {
      $result = $this->translationService
        ->requestTranslations($entity);
    } catch (LingotekPaymentRequiredException $exception) {
      $this
        ->messenger()
        ->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
    } 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 (LingotekApiException $exception) {
      $this
        ->messenger()
        ->addError(t('The request for @entity_type %title translation failed. Please try again.', [
        '@entity_type' => $entity
          ->getEntityTypeId(),
        '%title' => $entity
          ->label(),
      ]));
    }
  }
  else {
    $bundleInfos = $this->entityTypeBundleInfo
      ->getBundleInfo($entity
      ->getEntityTypeId());
    $this
      ->messenger()
      ->addWarning($this
      ->t('The @type %label has no profile assigned so it was not processed.', [
      '@type' => $bundleInfos[$entity
        ->bundle()]['label'],
      '%label' => $entity
        ->label(),
    ]));
  }
  return $result;
}