You are here

public function LingotekConfigTranslationService::requestTranslations in Lingotek Translation 8

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

Requests translations of a document in all the enabled locales.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity being requested for translations.

Overrides LingotekConfigTranslationServiceInterface::requestTranslations

File

src/LingotekConfigTranslationService.php, line 444
Contains \Drupal\lingotek\LingotekConfigTranslationService.

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function requestTranslations(ConfigEntityInterface &$entity) {
  $languages = [];
  if ($document_id = $this
    ->getDocumentId($entity)) {
    $target_languages = $this->languageManager
      ->getLanguages();
    $target_languages = array_filter($target_languages, function (LanguageInterface $language) {
      $configLanguage = ConfigurableLanguage::load($language
        ->getId());
      return $this->lingotekConfiguration
        ->isLanguageEnabled($configLanguage);
    });
    $entity_langcode = $entity
      ->language()
      ->getId();
    foreach ($target_languages as $langcode => $language) {
      $locale = $this->languageLocaleMapper
        ->getLocaleForLangcode($langcode);
      if ($langcode !== $entity_langcode) {
        $source_status = $this
          ->getSourceStatus($entity);
        $current_status = $this
          ->getTargetStatus($entity, $langcode);
        if ($current_status !== Lingotek::STATUS_PENDING && $current_status !== Lingotek::STATUS_CURRENT && $current_status !== Lingotek::STATUS_EDITED && $current_status !== Lingotek::STATUS_READY) {
          if ($this->lingotek
            ->addTarget($document_id, $locale, $this->lingotekConfiguration
            ->getConfigEntityProfile($entity))) {
            $languages[] = $langcode;
            $this
              ->setTargetStatus($entity, $langcode, Lingotek::STATUS_PENDING);

            // If the status was "Importing", and the target was added
            // successfully, we can ensure that the content is current now.
            if ($source_status == Lingotek::STATUS_IMPORTING) {
              $this
                ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
            }
          }
        }
      }
    }
  }
  return $languages;
}