You are here

public function LingotekConfigSubscriber::onConfigLanguageOverrideDelete in Lingotek Translation 8.2

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

Updates the Lingotek configuration when a field is deleted.

Parameters

\Drupal\Core\Config\ConfigCrudEvent $event: The configuration event.

File

src/EventSubscriber/LingotekConfigSubscriber.php, line 209

Class

LingotekConfigSubscriber
Updates config Lingotek translation status when saved.

Namespace

Drupal\lingotek\EventSubscriber

Code

public function onConfigLanguageOverrideDelete(LanguageConfigOverrideCrudEvent $event) {
  if (!drupal_installation_attempted()) {

    /** @var \Drupal\lingotek\LanguageLocaleMapperInterface $languageMapper */
    $languageMapper = \Drupal::service('lingotek.language_locale_mapper');
    $configOverride = $event
      ->getLanguageConfigOverride();
    $config_name = $configOverride
      ->getName();
    $mapper = $this
      ->getMapperFromConfigName($config_name);
    if ($mapper !== NULL) {
      if ($mapper instanceof ConfigEntityMapper) {
        $entity = $mapper
          ->getEntity();
        $document_id = $this->translationService
          ->getDocumentId($entity);
        $translation_statuses = \Drupal::service('lingotek')
          ->getDocumentTranslationStatuses($document_id);
        foreach ($translation_statuses as $lingotek_locale => $progress) {
          $drupal_language = $languageMapper
            ->getConfigurableLanguageForLocale($lingotek_locale);
          if ($drupal_language !== NULL && $drupal_language
            ->getId() === $configOverride
            ->getLangcode()) {
            if ($progress === Lingotek::PROGRESS_COMPLETE) {
              $this->translationService
                ->setTargetStatus($entity, $configOverride
                ->getLangcode(), Lingotek::STATUS_READY);
            }
            else {
              $this->translationService
                ->setTargetStatus($entity, $configOverride
                ->getLangcode(), Lingotek::STATUS_PENDING);
            }
            return;
          }
        }
      }
      else {
        $document_id = $this->translationService
          ->getConfigDocumentId($mapper);
        $translation_statuses = \Drupal::service('lingotek')
          ->getDocumentTranslationStatuses($document_id);
        foreach ($translation_statuses as $lingotek_locale => $progress) {
          $drupal_language = $languageMapper
            ->getConfigurableLanguageForLocale($lingotek_locale);
          if ($drupal_language
            ->getId() === $configOverride
            ->getLangcode()) {
            if ($progress === Lingotek::PROGRESS_COMPLETE) {
              $this->translationService
                ->setConfigTargetStatus($mapper, $configOverride
                ->getLangcode(), Lingotek::STATUS_READY);
            }
            else {
              $this->translationService
                ->setConfigTargetStatus($mapper, $configOverride
                ->getLangcode(), Lingotek::STATUS_PENDING);
            }
            return;
          }
        }
      }
    }
  }
}