diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index b6d498f..470cbb9 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2446,11 +2446,7 @@ function language_types_get_default() { * TRUE if more than one language is enabled. */ function language_multilingual() { - // The "language_count" variable stores the number of enabled languages to - // avoid unnecessarily querying the database when building the list of - // enabled languages on monolingual sites. - $language_count = Drupal::state()->get('language.count') ?: 1; - return $language_count > 1; + return Drupal::languageManager()->isMultilingual(); } /** diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index b277dcb..e676d20 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -154,17 +154,11 @@ public function reset($type = NULL) { * TRUE if more than one language is enabled, FALSE otherwise. */ public function isMultilingual() { - // @todo Inject state service here. if (!isset($this->state)) { - $container = \Drupal::getContainer(); - if ($container && $container->has('state')) { - $this->state = $container->get('state'); - } - else { - return FALSE; - } + // No state service in install time. + return FALSE; } - return ($this->state->get('language.count') ?: 1) > 1; + return ($this->state->get('language_count') ?: 1) > 1; } /** diff --git a/core/modules/language/language.install b/core/modules/language/language.install index 57f0b8e..2fdeb47 100644 --- a/core/modules/language/language.install +++ b/core/modules/language/language.install @@ -104,7 +104,7 @@ function language_schema() { */ function language_enable() { // Update the language count, if the module was disabled before, the - // language_count variable was forced to 1. + // language_count state was forced to 1. language_update_count(); } @@ -112,7 +112,7 @@ function language_enable() { * Implements hook_disable(). */ function language_disable() { - // Force the language_count variable to be 1, so that the when checking if the + // Force the language_count state to be 1, so that the when checking if the // site is multilingual (for example in language_multilingual()), the result // will be FALSE, because the language module is disabled. Drupal::state()->set('language_count', 1); diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 76206ac..32fc1d7 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -497,15 +497,15 @@ function language_save($language) { variable_set('language_default', (array) $language); } + // Kill the static cache in language_list(). + drupal_static_reset('language_list'); + // Update language count based on unlocked language count. language_update_count(); // Update weight of locked system languages. language_update_locked_weights(); - // Kill the static cache in language_list(). - drupal_static_reset('language_list'); - language_negotiation_include(); // Update URL Prefixes for all languages after the new default language is @@ -516,7 +516,7 @@ function language_save($language) { } /** - * Updates the language_count variable. + * Updates the language_count state. * * This is used to check if a site is multilingual or not. * @@ -547,13 +547,13 @@ function language_delete($langcode) { ->condition('langcode', $language->langcode) ->execute(); + drupal_static_reset('language_list'); + language_update_count(); // Update weight of locked system languages. language_update_locked_weights(); - drupal_static_reset('language_list'); - $t_args = array('%language' => $language->name, '%langcode' => $language->langcode); watchdog('language', 'The %language (%langcode) language has been removed.', $t_args); return TRUE; diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php index ebf1d47..8e255a9 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php @@ -116,10 +116,10 @@ function testLanguageList() { // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); $this->assertResponse(404, 'Language no longer found.'); - // Make sure the "language_count" variable has been updated correctly. + // Make sure the "language_count" state has been updated correctly. drupal_static_reset('language_list'); $languages = language_list(); - $language_count = $this->container->get('state')->get('language.count') ?: 1; + $language_count = $this->container->get('state')->get('language_count') ?: 1; $this->assertEqual($language_count, count($languages), 'Language count is correct.'); // Delete French. $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete')); @@ -133,8 +133,8 @@ function testLanguageList() { // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/fr'); $this->assertResponse(404, 'Language no longer found.'); - // Make sure the "language_count" variable has not changed. - $language_count = $this->container->get('state')->get('language.count') ?: 1; + // Make sure the "language_count" state has not changed. + $language_count = $this->container->get('state')->get('language_count') ?: 1; $this->assertEqual($language_count, count($languages), 'Language count is correct.'); // Ensure we can delete the English language. Right now English is the only diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index e4155b1..2a5e53b 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -121,7 +121,7 @@ function testUninstallProcess() { $this->assertTrue($result = !file_exists($js_file), t('JavaScript file deleted: %file', array('%file' => $result ? $js_file : t('found')))); // Check language count. - $language_count = $this->container->get('state')->get('language.count') ?: 1; + $language_count = $this->container->get('state')->get('language_count') ?: 1; $this->assertEqual($language_count, 1, t('Language count: %count', array('%count' => $language_count))); // Check language negotiation.