diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index c38fc10..22c5289 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -188,8 +188,6 @@ public function getLanguageName($langcode) { */ public function getDefaultLockedLanguages($weight = 0) { $languages = array(); - // By default set a high weight. - $weight = max($weight, 97); $locked_language = array( 'default' => FALSE, diff --git a/core/modules/language/config/install/language.entity.und.yml b/core/modules/language/config/install/language.entity.und.yml index 9db876b..67caf48 100644 --- a/core/modules/language/config/install/language.entity.und.yml +++ b/core/modules/language/config/install/language.entity.und.yml @@ -1,7 +1,7 @@ id: und label: 'Not specified' direction: 'ltr' -weight: 98 +weight: 1 locked: true status: true langcode: en diff --git a/core/modules/language/config/install/language.entity.zxx.yml b/core/modules/language/config/install/language.entity.zxx.yml index 9c88e04..7f02cf7 100644 --- a/core/modules/language/config/install/language.entity.zxx.yml +++ b/core/modules/language/config/install/language.entity.zxx.yml @@ -1,7 +1,7 @@ id: zxx label: 'Not applicable' direction: 'ltr' -weight: 99 +weight: 2 locked: true status: true langcode: en diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index 44b96fd..8fef8d2 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -72,7 +72,7 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu * * @var integer */ - protected $weight = NULL; + protected $weight = 0; /** * Locked languages cannot be edited. @@ -121,16 +121,6 @@ public function preSave(EntityStorageInterface $storage) { // For the uncommon case of custom languages the label should be given in // English. $this->langcode = 'en'; - - // When adding a new language the weight shouldn't be zero to avoid a - // reordering of the languages list when their names change i.e. interface - // translation. - if (is_null($this->getWeight())) { - // Fetch all configurable languages ordered by weight. - $languages = \Drupal::languageManager()->getLanguages($this::STATE_CONFIGURABLE); - $last_language = end($languages); - $this->setWeight($last_language->getWeight() + 1); - } } /** diff --git a/core/modules/language/src/Form/LanguageAddForm.php b/core/modules/language/src/Form/LanguageAddForm.php index fc27626..d44ce16 100644 --- a/core/modules/language/src/Form/LanguageAddForm.php +++ b/core/modules/language/src/Form/LanguageAddForm.php @@ -159,6 +159,11 @@ protected function copyFormValuesToEntity(EntityInterface $entity, array $form, $entity->set('id', $langcode); $entity->set('label', $label); $entity->set('direction', $direction); + // There is no weight on in the edit form. + // Fetch all configurable languages ordered by weight. + $languages = \Drupal::languageManager()->getLanguages(ConfigurableLanguage::STATE_CONFIGURABLE); + $last_language = end($languages); + $entity->setWeight($last_language->getWeight() + 1); } } diff --git a/core/modules/language/src/Tests/LanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageConfigurationTest.php index d94fcf4..7682021 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php @@ -29,9 +29,9 @@ class LanguageConfigurationTest extends WebTestBase { * Functional tests for adding, editing and deleting languages. */ function testLanguageConfiguration() { - // Ensure the after installing the language module the weight of the english + // Ensure the after installing the language module the weight of the English // language is still 0. - $this->assertEqual(ConfigurableLanguage::load('en')->getWeight(), 0, 'The english language has a weight of 0.'); + $this->assertEqual(ConfigurableLanguage::load('en')->getWeight(), 0, 'The English language has a weight of 0.'); // User to add and remove language. $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); @@ -108,22 +108,21 @@ function testLanguageConfiguration() { $this->rebuildContainer(); $this->assertRaw(t('The %language (%langcode) language has been removed.', array('%language' => 'English', '%langcode' => 'en'))); - // Ensure that french language has a weight of 1 after being created through the UI. + // Ensure that French language has a weight of 1 after being created through + // the UI. $french = ConfigurableLanguage::load('fr'); $this->assertEqual($french->getWeight(), 1, 'The French language has a weight of 1.'); - // Ensure that french language can now have a weight of 0. + // Ensure that French language can now have a weight of 0. $french->setWeight(0)->save(); $this->assertEqual($french->getWeight(), 0, 'The French language has a weight of 0.'); - // Ensure that new languages get the last weight by default. + // Ensure that new languages created through the API get a weight of 0. $afrikaans = ConfigurableLanguage::createFromLangcode('af'); $afrikaans->save(); - $this->assertEqual($afrikaans->getWeight(), 1, 'The Afrikaans language has a weight of 1.'); - $afrikaans->setWeight(0)->save(); $this->assertEqual($afrikaans->getWeight(), 0, 'The Afrikaans language has a weight of 0.'); - // Ensure that a new language can be created with a weight of 0. + // Ensure that a new language can be created with any weight. $arabic = ConfigurableLanguage::createFromLangcode('ar'); - $arabic->setWeight(0)->save(); - $this->assertEqual($arabic->getWeight(), 0, 'The Arabic language has a weight of 0.'); + $arabic->setWeight(4)->save(); + $this->assertEqual($arabic->getWeight(), 4, 'The Arabic language has a weight of 0.'); $edit = array( 'predefined_langcode' => 'de', @@ -131,6 +130,11 @@ function testLanguageConfiguration() { $this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language'); $language = $this->config('language.entity.de')->get(); $this->assertEqual($language['langcode'], 'en'); + + // Ensure that German language has a weight of 5 after being created through + // the UI. + $french = ConfigurableLanguage::load('de'); + $this->assertEqual($french->getWeight(), 5, 'The German language has a weight of 5.'); } /** diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php index 98362a7..2e8a3b3 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php @@ -504,8 +504,7 @@ protected function doTestLanguageFallback($entity_type) { $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode'); $languages = $this->languageManager->getLanguages(); $language = ConfigurableLanguage::load($languages[$langcode]->getId()); - // Make $language the last. - $language->set('weight', 4); + $language->set('weight', 1); $language->save(); $this->languageManager->reset();