function language_negotiation_url_prefixes_update

Same name in other branches
  1. 9 core/modules/language/language.module \language_negotiation_url_prefixes_update()
  2. 8.9.x core/modules/language/language.module \language_negotiation_url_prefixes_update()
  3. 10 core/modules/language/language.module \language_negotiation_url_prefixes_update()

Update the list of prefixes from the installed languages.

1 call to language_negotiation_url_prefixes_update()
ConfigurableLanguage::postSave in core/modules/language/src/Entity/ConfigurableLanguage.php

File

core/modules/language/language.module, line 113

Code

function language_negotiation_url_prefixes_update() {
    $config = \Drupal::configFactory()->getEditable('language.negotiation');
    $prefixes = $config->get('url.prefixes');
    foreach (\Drupal::languageManager()->getLanguages() as $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[$language->getId()])) {
            // For the default language, set the prefix to the empty string,
            // otherwise use the langcode.
            $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId();
        }
        // Otherwise we keep the configured prefix.
    }
    $config->set('url.prefixes', $prefixes)
        ->save(TRUE);
}

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