You are here

function locale_system_set_config_langcodes in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/locale/locale.module \locale_system_set_config_langcodes()

Updates default configuration when new modules or themes are installed.

3 calls to locale_system_set_config_langcodes()
LocaleConfigSubscriberTest::setUp in core/modules/locale/tests/src/Kernel/LocaleConfigSubscriberTest.php
locale_modules_installed in core/modules/locale/locale.module
Implements hook_modules_installed().
locale_themes_installed in core/modules/locale/locale.module
Implements hook_themes_installed().

File

core/modules/locale/locale.module, line 370
Enables the translation of the user interface to languages other than English.

Code

function locale_system_set_config_langcodes() {

  // Need to rewrite some default configuration language codes if the default
  // site language is not English.
  $default_langcode = \Drupal::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 or tour module may bring in default configuration from prior
    // components.
    $names = Locale::config()
      ->getComponentNames();
    foreach ($names as $name) {
      $config = \Drupal::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()) {
        $langcode = $config
          ->get('langcode');
        if (empty($langcode) || $langcode == 'en') {
          $config
            ->set('langcode', $default_langcode)
            ->save();
        }
      }
    }
  }
}