diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 20a53e7..499c81b 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -131,7 +131,7 @@ public function get($name) { * A configuration object. */ protected function doGet($name, $immutable = TRUE) { - if ($config = $this->loadMultiple(array($name), $immutable)) { + if ($config = $this->doLoadMultiple(array($name), $immutable)) { return $config[$name]; } else { @@ -158,7 +158,22 @@ protected function doGet($name, $immutable = TRUE) { /** * {@inheritdoc} */ - public function loadMultiple(array $names, $immutable = TRUE) { + public function loadMultiple(array $names) { + return $this->doLoadMultiple($names); + } + + /** + * Returns a list of configuration objects for the given names. + * + * @param array $names + * List of names of configuration objects. + * @param bool $immutable + * (optional) Create an immutable configuration objects. Defaults to TRUE. + * + * @return \Drupal\Core\Config\Config[]|\Drupal\Core\Config\ImmutableConfig[] + * List of successfully loaded configuration objects, keyed by name. + */ + protected function doLoadMultiple(array $names, $immutable = TRUE) { $list = array(); foreach ($names as $key => $name) { diff --git a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php index c58521e..f74be94 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php @@ -71,17 +71,17 @@ public function getEditable($name); * Returns a list of configuration objects for the given names. * * This will pre-load all requested configuration objects does not create - * new configuration objects. + * new configuration objects. This method always return immutable objects. + * ConfigFactoryInterface::getEditable() should be used to retrieve mutable + * configuration objects, one by one. * * @param array $names * List of names of configuration objects. - * @param bool $immutable - * (optional) Create an immutable configuration object. Defaults to TRUE. * - * @return \Drupal\Core\Config\Config[]|\Drupal\Core\Config\ImmutableConfig[] + * @return \Drupal\Core\Config\ImmutableConfig[] * List of successfully loaded configuration objects, keyed by name. */ - public function loadMultiple(array $names, $immutable = TRUE); + public function loadMultiple(array $names); /** * Resets and re-initializes configuration objects. Internal use only. diff --git a/core/modules/language/src/ConfigurableLanguageInterface.php b/core/modules/language/src/ConfigurableLanguageInterface.php index a4b794e..994f6c1 100644 --- a/core/modules/language/src/ConfigurableLanguageInterface.php +++ b/core/modules/language/src/ConfigurableLanguageInterface.php @@ -16,4 +16,15 @@ */ interface ConfigurableLanguageInterface extends ConfigEntityInterface, LanguageInterface { + /** + * Sets the weight of the language. + * + * @param int $weight + * The weight, used to order languages with larger positive weights sinking + * items toward the bottom of lists. + * + * @return $this + */ + public function setWeight($weight); + } diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index beb4d11..a4ca11b 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -343,23 +343,21 @@ public function getNativeLanguages() { * {@inheritdoc} */ public function updateLockedLanguageWeights() { - $max_weight = 0; + // Get the weight of the last configurable language. + $configurable_languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE); + $max_weight = end($configurable_languages)->getWeight(); - // Get maximum weight to update the system languages to keep them on bottom. - foreach ($this->getLanguages(LanguageInterface::STATE_CONFIGURABLE) as $language) { - if (!$language->isLocked()) { - $max_weight = max($max_weight, $language->getWeight()); - } - } - - // Loop locked languages to maintain the existing order. $locked_languages = $this->getLanguages(LanguageInterface::STATE_LOCKED); - $config_ids = array_map(function($language) { return 'language.entity.' . $language->getId(); }, $locked_languages); - foreach ($this->configFactory->loadMultiple($config_ids, FALSE) as $config) { - // Update system languages weight. - $max_weight++; - $config->set('weight', $max_weight); - $config->save(); + // 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(); + } } } diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index f2e128b..e52f763 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -130,7 +130,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { $language_manager = \Drupal::languageManager(); $language_manager->reset(); - if ($language_manager instanceof ConfigurableLanguageManagerInterface) { + if (!$this->isLocked() && $language_manager instanceof ConfigurableLanguageManagerInterface) { $language_manager->updateLockedLanguageWeights(); } @@ -231,6 +231,14 @@ public function getWeight() { } /** + * {@inheritdoc} + */ + public function setWeight($weight) { + $this->weight = $weight; + return $this; + } + + /** * Creates a configurable language object from a langcode. * * @param string $langcode