You are here

public function LingotekConfigTranslationService::downloadConfig in Lingotek Translation 3.6.x

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

Downloads a document to the Lingotek service.

Parameters

string $mapper_id: The entity being uploaded.

string $locale: Lingotek translation language which we want to modify.

Return value

bool TRUE if the document was downloaded successfully, FALSE if not.

Overrides LingotekConfigTranslationServiceInterface::downloadConfig

File

src/LingotekConfigTranslationService.php, line 1382

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function downloadConfig($mapper_id, $locale) {
  $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;
  }
  if ($document_id = $this
    ->getConfigDocumentId($mapper)) {
    $langcode = $this->languageLocaleMapper
      ->getConfigurableLanguageForLocale($locale)
      ->getId();
    $data = [];
    try {
      if ($this->lingotek
        ->getDocumentTranslationStatus($document_id, $locale) === TRUE) {
        $data = $this->lingotek
          ->downloadDocument($document_id, $locale);
      }
      else {
        return NULL;
      }
    } catch (LingotekApiException $exception) {

      // TODO: log issue
      $this
        ->setConfigTargetStatus($mapper, $langcode, Lingotek::STATUS_ERROR);
      return FALSE;
    }
    if ($data) {

      // Allow other modules to alter the data after it is downloaded.
      $config_names = $mapper
        ->getConfigNames();
      $config_name = reset($config_names);
      \Drupal::moduleHandler()
        ->invokeAll('lingotek_config_object_translation_presave', [
        &$data,
        $config_name,
      ]);

      // Check the real status, because it may still need review or anything.
      $status = $this->lingotek
        ->getDocumentTranslationStatus($document_id, $locale);
      $this
        ->saveConfigTargetData($mapper, $langcode, $data);

      // If the status was "Importing", and the target was added
      // successfully, we can ensure that the content is current now.
      $source_status = $this
        ->getConfigSourceStatus($mapper);
      if ($source_status == Lingotek::STATUS_IMPORTING) {
        $this
          ->setConfigSourceStatus($mapper, Lingotek::STATUS_CURRENT);
      }
      if ($source_status == Lingotek::STATUS_EDITED) {
        $this
          ->setConfigTargetStatus($mapper, $langcode, Lingotek::STATUS_EDITED);
      }
      elseif ($status === TRUE) {
        $this
          ->setConfigTargetStatus($mapper, $langcode, Lingotek::STATUS_CURRENT);
      }
      else {
        $this
          ->setConfigTargetStatus($mapper, $langcode, Lingotek::STATUS_INTERMEDIATE);
      }
      return TRUE;
    }
  }
  if ($this
    ->getConfigSourceStatus($mapper) == Lingotek::STATUS_DISABLED) {
    $this
      ->setConfigTargetStatuses($mapper, Lingotek::STATUS_DISABLED);
  }
  return FALSE;
}