You are here

public function LingotekConfigTranslationService::requestConfigTranslations in Lingotek Translation 3.3.x

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

Request all translations for a given mapper in all locales.

Parameters

string $mapper_id: The entity which target we want to add.

Throws

\Drupal\lingotek\Exception\LingotekPaymentRequiredException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekConfigTranslationServiceInterface::requestConfigTranslations

File

src/LingotekConfigTranslationService.php, line 1194

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function requestConfigTranslations($mapper_id) {
  $mapper = $this->mappers[$mapper_id];
  $profile = $this->lingotekConfiguration
    ->getConfigProfile($mapper_id);
  if ($profile
    ->id() === Lingotek::PROFILE_DISABLED || $this
    ->getConfigSourceStatus($mapper) === Lingotek::STATUS_CANCELLED) {
    return FALSE;
  }
  $languages = [];
  if ($document_id = $this
    ->getConfigDocumentId($mapper)) {
    $target_languages = $this->languageManager
      ->getLanguages();
    $source_langcode = $mapper
      ->getLangcode();
    foreach ($target_languages as $langcode => $language) {
      $locale = $this->languageLocaleMapper
        ->getLocaleForLangcode($langcode);
      if ($langcode !== $source_langcode) {
        $source_status = $this
          ->getConfigSourceStatus($mapper);
        $current_status = $this
          ->getConfigTargetStatus($mapper, $langcode);
        if ($current_status !== Lingotek::STATUS_PENDING && $current_status !== Lingotek::STATUS_CURRENT && $current_status !== Lingotek::STATUS_EDITED && $current_status !== Lingotek::STATUS_READY) {
          try {
            $result = $this->lingotek
              ->addTarget($document_id, $locale, $this->lingotekConfiguration
              ->getConfigProfile($mapper
              ->getPluginId()));
          } catch (LingotekDocumentLockedException $exception) {
            $this
              ->setConfigDocumentId($mapper, $exception
              ->getNewDocumentId());
            throw $exception;
          } catch (LingotekDocumentArchivedException $exception) {
            $this
              ->setConfigDocumentId($mapper, NULL);
            $this
              ->deleteConfigMetadata($mapper_id);
            throw $exception;
          } catch (LingotekPaymentRequiredException $exception) {
            throw $exception;
          } catch (LingotekApiException $exception) {
            throw $exception;
          }
          if ($result) {
            $languages[] = $langcode;
            $this
              ->setConfigTargetStatus($mapper, $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
                ->setConfigSourceStatus($mapper, Lingotek::STATUS_CURRENT);
            }
          }
        }
        else {
          return FALSE;
        }
      }
    }
  }
  if ($this
    ->getConfigSourceStatus($mapper) == Lingotek::STATUS_DISABLED) {
    $this
      ->setConfigTargetStatuses($mapper, Lingotek::STATUS_DISABLED);
  }
  return $languages;
}