diff --git a/core/modules/language/language.module b/core/modules/language/language.module index e92baa24904..6d9f6994084 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -311,8 +311,13 @@ function language_negotiation_url_domains() { */ function language_modules_installed($modules) { if (!in_array('language', $modules)) { + // Since newly (un)installed modules may change the default settings for + // non-locked language types (e.g. content language), we need to resave the + // language type configuration. + /** @var \Drupal\language\LanguageNegotiatorInterface $negotiator */ $negotiator = \Drupal::service('language_negotiator'); - $negotiator->updateConfiguration(array()); + $configurable = \Drupal::config('language.types')->get('configurable'); + $negotiator->updateConfiguration($configurable); $negotiator->purgeConfiguration(); } else { diff --git a/core/modules/language/src/Tests/LanguageNegotiationInfoTest.php b/core/modules/language/src/Tests/LanguageNegotiationInfoTest.php index 8ef3c098434..511c1474530 100644 --- a/core/modules/language/src/Tests/LanguageNegotiationInfoTest.php +++ b/core/modules/language/src/Tests/LanguageNegotiationInfoTest.php @@ -23,14 +23,14 @@ class LanguageNegotiationInfoTest extends WebTestBase { * * @var array */ - public static $modules = array('language'); + public static $modules = ['language', 'content_translation']; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'view the administration theme')); + $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'view the administration theme', 'administer modules']); $this->drupalLogin($admin_user); $this->drupalPostForm('admin/config/regional/language/add', array('predefined_langcode' => 'it'), t('Add language')); } @@ -174,4 +174,41 @@ class LanguageNegotiationInfoTest extends WebTestBase { } } } + + /** + * Tests altering config of configurable language types. + */ + public function testConfigLangTypeAlterations() { + // Default of config. + $test_type = LanguageInterface::TYPE_CONTENT; + $this->assertFalse($this->isLanguageTypeConfigurable($test_type), 'Language type is not configurable.'); + + // Editing config. + $edit = [$test_type . '[configurable]' => TRUE]; + $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + $this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is now configurable.'); + + // After installing another module, the config should be the same. + $this->drupalPostForm('admin/modules', ['modules[Testing][test_module][enable]' => 1], t('Install')); + $this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.'); + + // After uninstalling the other module, the config should be the same. + $this->drupalPostForm('admin/modules/uninstall', ['uninstall[test_module]' => 1], t('Uninstall')); + $this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.'); + } + + /** + * Checks whether the given language type is configurable. + * + * @param string $type + * The language type. + * + * @return bool + * TRUE if the specified language type is configurable, FALSE otherwise. + */ + protected function isLanguageTypeConfigurable($type) { + $configurable_types = $this->config('language.types')->get('configurable'); + return in_array($type, $configurable_types); + } + } diff --git a/core/modules/language/tests/test_module/test_module.info.yml b/core/modules/language/tests/test_module/test_module.info.yml new file mode 100644 index 00000000000..f68226f86b1 --- /dev/null +++ b/core/modules/language/tests/test_module/test_module.info.yml @@ -0,0 +1,6 @@ +name: 'Test Module' +type: module +description: 'Support module for testing.' +package: Testing +version: VERSION +core: 8.x