LocaleConfigManager::updateConfigTranslations

public LocaleConfigManager::updateConfigTranslations(array $names, array $langcodes = array())

Updates all configuration translations for the names / languages provided.

To be used when interface translation changes result in the need to update configuration translations to keep them in sync.

Parameters

array $names: Array of names of configuration objects to update.

array $langcodes: (optional) Array of language codes to update. Defaults to all configurable languages.

Return value

int Total number of configuration override and active configuration objects updated (saved or removed).

File

core/modules/locale/src/LocaleConfigManager.php, line 567

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

public function updateConfigTranslations(array $names, array $langcodes = array()) {
  $langcodes = $langcodes ? $langcodes : array_keys($this->languageManager->getLanguages());
  $count = 0;
  foreach ($names as $name) {
    $translatable = $this->getTranslatableDefaultConfig($name);
    if (empty($translatable)) {
      // If there is nothing translatable in this configuration or not
      // supported, skip it.
      continue;
    }

    $active_langcode = $this->getActiveConfigLangcode($name);
    $active = $this->configStorage->read($name);

    foreach ($langcodes as $langcode) {
      $processed = $this->processTranslatableData($name, $active, $translatable, $langcode);
      // If the language code is not the same as the active storage
      // language, we should update the configuration override.
      if ($langcode != $active_langcode) {
        $override = $this->languageManager->getLanguageConfigOverride($langcode, $name);
        // Filter out locale managed configuration keys so that translations
        // removed from Locale will be reflected in the config override.
        $data = $this->filterOverride($override->get(), $translatable);
        if (!empty($processed)) {
          // Merge in the Locale managed translations with existing data.
          $data = NestedArray::mergeDeepArray(array($data, $processed), TRUE);
        }
        if (empty($data) && !$override->isNew()) {
          // The configuration override contains Locale overrides that no
          // longer exist.
          $this->deleteTranslationOverride($name, $langcode);
          $count++;
        }
        elseif (!empty($data)) {
          // Update translation data in configuration override.
          $this->saveTranslationOverride($name, $langcode, $data);
          $count++;
        }
      }
      elseif (locale_is_translatable($langcode)) {
        // If the language code is the active storage language, we should
        // update. If it is English, we should only update if English is also
        // translatable.
        $active = NestedArray::mergeDeepArray(array($active, $processed), TRUE);
        $this->saveTranslationActive($name, $active);
        $count++;
      }
    }
  }
  return $count;
}
doc_Drupal
2016-10-29 09:23:56
Comments
Leave a Comment

Please login to continue.