function ConfigurableLanguage::updateUrlPrefixes

Update the list of prefixes from the installed languages.

File

core/modules/language/src/Entity/ConfigurableLanguage.php, line 304

Class

ConfigurableLanguage
Defines the ConfigurableLanguage entity.

Namespace

Drupal\language\Entity

Code

protected function updateUrlPrefixes() : void {
  $config = \Drupal::configFactory()->getEditable('language.negotiation');
  $prefixes = $config->get('url.prefixes');
  foreach ($this->languageManager()
    ->getLanguages() as $langcode => $language) {
    // The prefix for this language should be updated if it's not assigned yet
    // or the prefix is set to the empty string.
    if (empty($prefixes[$langcode])) {
      // For the default language, set the prefix to the empty string,
      // otherwise use the langcode.
      $prefixes[$langcode] = $language->isDefault() ? '' : $langcode;
    }
    // Otherwise we keep the configured prefix.
  }
  $config->set('url.prefixes', $prefixes)
    ->save();
}

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