diff --git a/core/modules/language/src/Config/LanguageConfigOverride.php b/core/modules/language/src/Config/LanguageConfigOverride.php index d64dda7..11f031c 100644 --- a/core/modules/language/src/Config/LanguageConfigOverride.php +++ b/core/modules/language/src/Config/LanguageConfigOverride.php @@ -27,6 +27,13 @@ class LanguageConfigOverride extends StorableConfigBase { protected $eventDispatcher; /** + * Whether or not configuration translations are currently being updated. + * + * @var bool + */ + protected $isUpdating = FALSE; + + /** * Constructs a language override object. * * @param string $name @@ -44,6 +51,7 @@ public function __construct($name, StorageInterface $storage, TypedConfigManager $this->storage = $storage; $this->typedConfigManager = $typed_config; $this->eventDispatcher = $event_dispatcher; + $this->isUpdating = $isUpdating; } /** @@ -85,4 +93,20 @@ public function getLangcode() { return $this->getLangcodeFromCollectionName($this->getStorage()->getCollectionName()); } + /** + * Indicates whether configuration translations are currently being updated. + * + * @param bool $isUpdating + * Optional. Set to true if configuration translations are currently being updated. + * + * @return bool + * Whether or not configuration translations are currently being updated. + */ + public function isUpdatingConfigTranslations($isUpdating = NULL) { + if (isset($isUpdating)) { + $this->isUpdating = $isUpdating; + } + return $this->isUpdating; + } + } diff --git a/core/modules/language/src/Config/LanguageConfigOverrideCrudEvent.php b/core/modules/language/src/Config/LanguageConfigOverrideCrudEvent.php index 3b91d07..88b966a 100644 --- a/core/modules/language/src/Config/LanguageConfigOverrideCrudEvent.php +++ b/core/modules/language/src/Config/LanguageConfigOverrideCrudEvent.php @@ -29,8 +29,9 @@ class LanguageConfigOverrideCrudEvent extends Event { * @param \Drupal\language\Config\LanguageConfigOverride $override * Configuration object. */ - public function __construct(LanguageConfigOverride $override) { + public function __construct(LanguageConfigOverride $override, $isUpdating) { $this->override = $override; + $this->isUpdating = $isUpdating; } /** diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index 7bc846e..158d9ce 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -66,13 +66,6 @@ class LocaleConfigManager { protected $typedConfigManager; /** - * Whether or not configuration translations are currently being updated. - * - * @var bool - */ - protected $isUpdating = FALSE; - - /** * Creates a new typed configuration manager. * * @param \Drupal\Core\Config\StorageInterface $config_storage @@ -163,9 +156,9 @@ protected function compareConfigData(array $default, $updated) { * Configuration data to be saved, that will be only the translated values. */ public function saveTranslationData($name, $langcode, array $data) { - $this->isUpdating = TRUE; - $this->languageManager->getLanguageConfigOverride($langcode, $name)->setData($data)->save(); - $this->isUpdating = FALSE; + $override = $this->languageManager->getLanguageConfigOverride($langcode, $name)->setData($data); + $override->isUpdatingConfigTranslations(TRUE); + $override->save(); } /** @@ -177,9 +170,9 @@ public function saveTranslationData($name, $langcode, array $data) { * Language code. */ public function deleteTranslationData($name, $langcode) { - $this->isUpdating = TRUE; - $this->languageManager->getLanguageConfigOverride($langcode, $name)->delete(); - $this->isUpdating = FALSE; + $override = $this->languageManager->getLanguageConfigOverride($langcode, $name); + $override->isUpdatingConfigTranslations(TRUE); + $override->delete(); } /** @@ -217,7 +210,6 @@ public function getComponentNames(array $components) { * Array of language codes. */ public function deleteComponentTranslations(array $components, array $langcodes) { - $this->isUpdating = TRUE; $names = $this->getComponentNames($components); if ($names && $langcodes) { foreach ($names as $name) { @@ -226,7 +218,6 @@ public function deleteComponentTranslations(array $components, array $langcodes) } } } - $this->isUpdating = FALSE; } /** @@ -254,12 +245,12 @@ public function getStringNames(array $lids) { * Language code to delete. */ public function deleteLanguageTranslations($langcode) { - $this->isUpdating = TRUE; $storage = $this->languageManager->getLanguageConfigOverrideStorage($langcode); foreach ($storage->listAll() as $name) { - $this->languageManager->getLanguageConfigOverride($langcode, $name)->delete(); + $override = $this->languageManager->getLanguageConfigOverride($langcode, $name); + $override->isUpdatingConfigTranslations(TRUE); + $override->delete(); } - $this->isUpdating = FALSE; } /** @@ -345,14 +336,4 @@ public function hasTranslation($name, LanguageInterface $language) { return !$translation->isNew(); } - /** - * Indicates whether configuration translations are currently being updated. - * - * @return bool - * Whether or not configuration translations are currently being updated. - */ - public function isUpdatingConfigTranslations() { - return $this->isUpdating; - } - } diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index e89a115..17bcba3 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -83,7 +83,7 @@ public static function getSubscribedEvents() { public function onSave(LanguageConfigOverrideCrudEvent $event) { // Do not mark strings as customized when community translations are being // imported. - if ($this->localeConfigManager->isUpdatingConfigTranslations()) { + if ($event->getLanguageConfigOverride()->isUpdatingConfigTranslations()) { $callable = [$this, 'saveTranslation']; } else { @@ -100,7 +100,7 @@ public function onSave(LanguageConfigOverrideCrudEvent $event) { * The language configuration event. */ public function onDelete(LanguageConfigOverrideCrudEvent $event) { - if ($this->localeConfigManager->isUpdatingConfigTranslations()) { + if ($event->getLanguageConfigOverride()->isUpdatingConfigTranslations()) { $callable = [$this, 'deleteTranslation']; } else {