function ConfigurableLanguageManager::updateLockedLanguageWeights

Same name in other branches
  1. 9 core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::updateLockedLanguageWeights()
  2. 8.9.x core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::updateLockedLanguageWeights()
  3. 11.x core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::updateLockedLanguageWeights()

Overrides ConfigurableLanguageManagerInterface::updateLockedLanguageWeights

File

core/modules/language/src/ConfigurableLanguageManager.php, line 344

Class

ConfigurableLanguageManager
Overrides default LanguageManager to provide configured languages.

Namespace

Drupal\language

Code

public function updateLockedLanguageWeights() {
    // Get the weight of the last configurable language.
    $configurable_languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
    $max_weight = end($configurable_languages)->getWeight();
    $locked_languages = $this->getLanguages(LanguageInterface::STATE_LOCKED);
    // Update locked language weights to maintain the existing order, if
    // necessary.
    if (reset($locked_languages)->getWeight() <= $max_weight) {
        foreach ($locked_languages as $language) {
            // Update system languages weight.
            $max_weight++;
            ConfigurableLanguage::load($language->getId())
                ->setWeight($max_weight)
                ->save();
        }
    }
}

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