You are here

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

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

Checks the status of the translation in the Lingotek service.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity which status we want to check.

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

Return value

bool True if the entity is checked successfully.

Overrides LingotekConfigTranslationServiceInterface::checkTargetStatus

File

src/LingotekConfigTranslationService.php, line 640

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function checkTargetStatus(ConfigEntityInterface &$entity, $locale) {
  $profile = $this->lingotekConfiguration
    ->getConfigEntityProfile($entity);
  $langcode = $this->languageLocaleMapper
    ->getConfigurableLanguageForLocale($locale)
    ->getId();
  if ($profile
    ->id() === Lingotek::PROFILE_DISABLED || $this
    ->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED) {
    return FALSE;
  }
  if ($profile !== NULL && $profile
    ->hasDisabledTarget($langcode)) {
    return FALSE;
  }
  $current_status = $this
    ->getTargetStatus($entity, $langcode);
  $document_id = $this
    ->getDocumentId($entity);
  $source_status = $this
    ->getSourceStatus($entity);
  if (($current_status == Lingotek::STATUS_PENDING || $current_status == Lingotek::STATUS_EDITED) && $source_status !== Lingotek::STATUS_EDITED) {
    $translation_status = $this->lingotek
      ->getDocumentTranslationStatus($document_id, $locale);
    if ($translation_status === Lingotek::STATUS_CANCELLED) {
      $this
        ->setTargetStatus($entity, $langcode, Lingotek::STATUS_CANCELLED);
    }
    elseif ($translation_status === TRUE) {
      $current_status = Lingotek::STATUS_READY;
      $this
        ->setTargetStatus($entity, $langcode, $current_status);
    }
    elseif ($this->lingotek
      ->downloadDocument($document_id, $locale)) {

      // TODO: Set Status to STATUS_READY_INTERIM when that status is
      // available. See ticket https://www.drupal.org/node/2850548
    }
  }
  if ($this
    ->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
    $this
      ->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
  }
  return $current_status;
}