diff --git a/core/modules/ckeditor/src/Tests/CKEditorTest.php b/core/modules/ckeditor/src/Tests/CKEditorTest.php index caf0345..02dc2f4 100644 --- a/core/modules/ckeditor/src/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/src/Tests/CKEditorTest.php @@ -383,6 +383,7 @@ function testLanguages() { */ function testJSTranslation() { $this->enableModules(array('language', 'locale')); + $this->installConfig(['language']); $this->installSchema('locale', 'locales_source'); $this->installSchema('locale', 'locales_location'); $this->installSchema('locale', 'locales_target'); diff --git a/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php b/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php index b96819e..1b07239 100644 --- a/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php +++ b/core/modules/config/src/Tests/ConfigLanguageOverrideTest.php @@ -29,7 +29,7 @@ class ConfigLanguageOverrideTest extends KernelTestBase { */ protected function setUp() { parent::setUp(); - $this->installConfig(array('config_test')); + $this->installConfig(array('config_test', 'language')); } /** diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index a754654..d029714 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -121,6 +121,17 @@ 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. The english language is special cased because it is provided + // as default configuration with a valid weight of 0. + if ($this->id != 'en' && $this->isNew() && !$this->isLocked() && $this->getWeight() == 0) { + // Fetch all configurable languages ordered by weight. + $languages = \Drupal::languageManager()->getLanguages($this::STATE_CONFIGURABLE); + $last_language = end($languages); + $this->setWeight($last_language->getWeight() + 1); + } } /** @@ -131,7 +142,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { $language_manager = \Drupal::languageManager(); $language_manager->reset(); - if (!$this->isLocked() && $language_manager instanceof ConfigurableLanguageManagerInterface) { + if (!$this->isLocked() && $language_manager instanceof ConfigurableLanguageManagerInterface && !$this->isSyncing()) { $language_manager->updateLockedLanguageWeights(); } @@ -173,7 +184,8 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti parent::postDelete($storage, $entities); $language_manager = \Drupal::languageManager(); $language_manager->reset(); - if ($language_manager instanceof ConfigurableLanguageManagerInterface) { + $entity = reset($entities); + if ($language_manager instanceof ConfigurableLanguageManagerInterface && !$entity->isUninstalling() && !$entity->isSyncing()) { $language_manager->updateLockedLanguageWeights(); } // If after deleting this language the site will become monolingual, we need diff --git a/core/modules/language/src/Tests/EntityDefaultLanguageTest.php b/core/modules/language/src/Tests/EntityDefaultLanguageTest.php index b3b109a..0878cad 100644 --- a/core/modules/language/src/Tests/EntityDefaultLanguageTest.php +++ b/core/modules/language/src/Tests/EntityDefaultLanguageTest.php @@ -30,7 +30,7 @@ class EntityDefaultLanguageTest extends KernelTestBase { */ public function setUp() { parent::setUp(); - + $this->installConfig(['language']); $this->installEntitySchema('user'); // Activate Spanish language, so there are two languages activated. diff --git a/core/modules/language/src/Tests/LanguageConfigOverrideInstallTest.php b/core/modules/language/src/Tests/LanguageConfigOverrideInstallTest.php index 0364079..9392301 100644 --- a/core/modules/language/src/Tests/LanguageConfigOverrideInstallTest.php +++ b/core/modules/language/src/Tests/LanguageConfigOverrideInstallTest.php @@ -24,6 +24,14 @@ class LanguageConfigOverrideInstallTest extends KernelTestBase { public static $modules = array('language', 'config_events_test'); /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $this->installConfig(['language']); + } + + /** * Tests the configuration events are not fired during install of overrides. */ public function testLanguageConfigOverrideInstall() { diff --git a/core/modules/language/src/Tests/LanguageListTest.php b/core/modules/language/src/Tests/LanguageListTest.php index 8ec846c..22a638f 100644 --- a/core/modules/language/src/Tests/LanguageListTest.php +++ b/core/modules/language/src/Tests/LanguageListTest.php @@ -35,6 +35,10 @@ function testLanguageList() { $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); $this->drupalLogin($admin_user); + // Get the weight of the last language. + $languages = \Drupal::service('language_manager')->getLanguages(); + $last_language_weight = end($languages)->getWeight(); + // Add predefined language. $edit = array( 'predefined_langcode' => 'fr', @@ -43,6 +47,14 @@ function testLanguageList() { $this->assertText('French', 'Language added successfully.'); $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE])); + // Get the weight of the last language and check that the weight is one unit + // heavier and than the last configurable language. + $this->rebuildContainer(); + $languages = \Drupal::service('language_manager')->getLanguages(); + $last_language = end($languages); + $this->assertEqual($last_language->getWeight(), $last_language_weight + 1); + $this->assertEqual($last_language->getId(), $edit['predefined_langcode']); + // Add custom language. $langcode = 'xx'; $name = $this->randomMachineName(16); diff --git a/core/modules/locale/src/Tests/LocaleConfigManagerTest.php b/core/modules/locale/src/Tests/LocaleConfigManagerTest.php index 4cc9fb2..299f366 100644 --- a/core/modules/locale/src/Tests/LocaleConfigManagerTest.php +++ b/core/modules/locale/src/Tests/LocaleConfigManagerTest.php @@ -29,7 +29,7 @@ class LocaleConfigManagerTest extends KernelTestBase { */ public function testHasTranslation() { $this->installSchema('locale', array('locales_location')); - $this->installConfig(array('locale_test')); + $this->installConfig(array('locale_test', 'language')); $locale_config_manager = \Drupal::service('locale.config.typed'); $language = ConfigurableLanguage::createFromLangcode('de'); diff --git a/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php b/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php index f3f7415..40fea1a 100644 --- a/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php +++ b/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php @@ -72,7 +72,7 @@ protected function setUp() { $this->installSchema('locale', ['locales_source', 'locales_target', 'locales_location']); - $this->installConfig(['locale_test']); + $this->installConfig(['locale_test', 'language']); ConfigurableLanguage::createFromLangcode($this->langcode)->save(); } diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php index 2e8a3b3..98362a7 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php @@ -504,7 +504,8 @@ protected function doTestLanguageFallback($entity_type) { $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode'); $languages = $this->languageManager->getLanguages(); $language = ConfigurableLanguage::load($languages[$langcode]->getId()); - $language->set('weight', 1); + // Make $language the last. + $language->set('weight', 4); $language->save(); $this->languageManager->reset();