You are here

public function LingotekContentTranslationService::setTargetStatuses in Lingotek Translation 8.2

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

Sets the translation status of all translations of a given entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity which status we want to change.

int $status: Status of the translation. Use Lingotek constants.

Return value

\Drupal\Core\Entity\ContentEntityInterface

Overrides LingotekContentTranslationServiceInterface::setTargetStatuses

11 calls to LingotekContentTranslationService::setTargetStatuses()
LingotekContentTranslationService::addTarget in src/LingotekContentTranslationService.php
Request a translation for a given entity in the given locale.
LingotekContentTranslationService::cancelDocument in src/LingotekContentTranslationService.php
Cancels a document from the server.
LingotekContentTranslationService::cancelDocumentTarget in src/LingotekContentTranslationService.php
Cancels a translation for a given entity in the given locale.
LingotekContentTranslationService::checkSourceStatus in src/LingotekContentTranslationService.php
Checks the source is uploaded correctly.
LingotekContentTranslationService::checkTargetStatus in src/LingotekContentTranslationService.php
Gets the current status of the target translation.

... See full list

File

src/LingotekContentTranslationService.php, line 383

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function setTargetStatuses(ContentEntityInterface &$entity, $status) {
  $target_languages = $this->languageManager
    ->getLanguages();
  $entity_langcode = $entity
    ->getUntranslated()
    ->language()
    ->getId();
  foreach ($target_languages as $langcode => $language) {
    if ($langcode != $entity_langcode && ($current_status = $this
      ->getTargetStatus($entity, $langcode))) {
      if ($current_status === Lingotek::STATUS_PENDING && $status === Lingotek::STATUS_REQUEST) {

        // Don't allow to pass from pending to request. We have been already
        // requested this one.
        continue;
      }
      if (in_array($current_status, [
        Lingotek::STATUS_UNTRACKED,
        Lingotek::STATUS_REQUEST,
        Lingotek::STATUS_DISABLED,
        NULL,
      ]) && $status === Lingotek::STATUS_PENDING) {
        continue;
      }
      if ($current_status == $status) {
        continue;
      }
      if ($current_status != Lingotek::STATUS_EDITED && $current_status !== Lingotek::STATUS_CURRENT) {
        $this
          ->setTargetStatus($entity, $langcode, $status);
      }
      elseif ($current_status == Lingotek::STATUS_EDITED && in_array($status, [
        Lingotek::STATUS_CURRENT,
        Lingotek::STATUS_PENDING,
      ])) {
        $this
          ->setTargetStatus($entity, $langcode, $status);
      }
      if ($status === Lingotek::STATUS_CANCELLED) {
        $this
          ->setTargetStatus($entity, $langcode, $status);
      }
      if ($status === Lingotek::STATUS_DISABLED) {
        $this
          ->setTargetStatus($entity, $langcode, $status);
      }
    }
  }
}