You are here

public function ConfigurableLanguageManager::updateLockedLanguageWeights in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::updateLockedLanguageWeights()

Updates locked system language weights.

Overrides ConfigurableLanguageManagerInterface::updateLockedLanguageWeights

File

core/modules/language/src/ConfigurableLanguageManager.php, line 349
Contains \Drupal\language\ConfigurableLanguageManager.

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();
    }
  }
}