function LocaleConfigManager::updateDefaultConfigLangcodes

Same name and namespace in other branches
  1. 9 core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::updateDefaultConfigLangcodes()
  2. 11.x core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::updateDefaultConfigLangcodes()

Updates default configuration when new modules or themes are installed.

File

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

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

public function updateDefaultConfigLangcodes() {
  $this->isUpdatingFromLocale = TRUE;
  // Need to rewrite some default configuration language codes if the default
  // site language is not English.
  $default_langcode = $this->languageManager
    ->getDefaultLanguage()
    ->getId();
  if ($default_langcode != 'en') {
    // Update active configuration copies of all prior shipped configuration if
    // they are still English. It is not enough to change configuration shipped
    // with the components just installed, because installing a component such
    // as views may bring in default configuration from prior components.
    $names = $this->getComponentNames();
    foreach ($names as $name) {
      $config = $this->configFactory
        ->reset($name)
        ->getEditable($name);
      // Should only update if still exists in active configuration. If locale
      // module is enabled later, then some configuration may not exist anymore.
      if (!$config->isNew()) {
        $typed_config = $this->typedConfigManager
          ->createFromNameAndData($config->getName(), $config->getRawData());
        $langcode = $config->get('langcode');
        // Only set a `langcode` if this config actually contains translatable
        // data.
        // @see \Drupal\Core\Config\Plugin\Validation\Constraint\LangcodeRequiredIfTranslatableValuesConstraint
        if (!empty($this->getTranslatableData($typed_config)) && (empty($langcode) || $langcode == 'en')) {
          $config->set('langcode', $default_langcode)
            ->save();
        }
      }
    }
  }
  $this->isUpdatingFromLocale = FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.