You are here

public function LingotekConfigTranslationService::cancelDocumentTarget in Lingotek Translation 4.0.x

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

Cancels a translation for a given entity in the given locale.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface &$entity: The entity which target we want to cancel.

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

Throws

\Drupal\lingotek\Exception\LingotekDocumentTargetAlreadyCompletedException If the target was already completed.

Overrides LingotekConfigTranslationServiceInterface::cancelDocumentTarget

File

src/LingotekConfigTranslationService.php, line 918

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function cancelDocumentTarget(ConfigEntityInterface &$entity, $locale) {
  $profile = $this->lingotekConfiguration
    ->getConfigEntityProfile($entity);
  if ($profile
    ->id() === Lingotek::PROFILE_DISABLED || $this
    ->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED) {
    return FALSE;
  }
  $source_langcode = $entity
    ->language()
    ->getId();
  $source_locale = $this->languageLocaleMapper
    ->getLocaleForLangcode($source_langcode);
  if ($locale == $source_locale) {

    // This is not a target, but the source language itself.
    return FALSE;
  }
  if ($document_id = $this
    ->getDocumentId($entity)) {
    $drupal_language = $this->languageLocaleMapper
      ->getConfigurableLanguageForLocale($locale);
    if ($this->lingotek
      ->cancelDocumentTarget($document_id, $locale)) {
      $this
        ->setTargetStatus($entity, $drupal_language
        ->id(), Lingotek::STATUS_CANCELLED);
      return TRUE;
    }
  }
  if ($this
    ->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
    $this
      ->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
  }
  return FALSE;
}