diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 0dd19d5..4dcf481 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2743,7 +2743,8 @@ function language($type, $reset = FALSE) { * name and its value is its configurability (TRUE/FALSE). */ function language_types_get_all() { - return array_keys(variable_get('language_types', language_types_get_default())); + $language_types = config('language.detection')->get('types') ?: language_types_get_default(); + return array_keys($language_types); } /** * Returns a list of the built-in language types. @@ -2767,10 +2768,10 @@ 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. - return variable_get('language_count', 1) > 1; + // The "language.detection.count" variable stores the number of enabled + // languages to avoid unnecessarily querying the database when building the + // list of enabled languages on monolingual sites. + return state('language.detection')->get('count') > 1; } /** @@ -2931,13 +2932,7 @@ function language_is_locked($langcode) { * A language object. */ function language_default() { - $info = variable_get('language_default', array( - 'langcode' => 'en', - 'name' => 'English', - 'direction' => 0, - 'weight' => 0, - 'locked' => 0, - )); + $info = config('language.detection')->get('default'); $info['default'] = TRUE; return new Language($info); } diff --git a/core/includes/language.inc b/core/includes/language.inc index 74d5752..cade907 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -166,11 +166,11 @@ function language_types_info() { * the user interface. * * @param $stored - * (optional) By default, retrieves values from the 'language_types' variable - * to avoid unnecessary hook invocations. If set to FALSE, retrieves values - * from the actual language type definitions. This allows reaction to + * (optional) By default, retrieves values from the language.detection.types + * variable to avoid unnecessary hook invocations. If set to FALSE, retrieves + * values from the actual language type definitions. This allows reaction to * alterations performed on the definitions by modules installed after the - * 'language_types' variable is set. + * language.detection.types variable is set. * * @return * An array of language type names. @@ -179,7 +179,7 @@ function language_types_get_configurable($stored = TRUE) { $configurable = &drupal_static(__FUNCTION__); if ($stored && !isset($configurable)) { - $types = variable_get('language_types', language_types_get_default()); + $types = config('language.detection')->get('types') ?: language_types_get_default(); $configurable = array_keys(array_filter($types)); } @@ -203,13 +203,16 @@ function language_types_get_configurable($stored = TRUE) { * An array of language types. */ function language_types_disable($types) { - $enabled_types = variable_get('language_types', language_types_get_default()); + $language_settings = config('language.detection'); + $enabled_types = $language_settings->get('types') ?: language_types_get_default(); foreach ($types as $type) { unset($enabled_types[$type]); } - variable_set('language_types', $enabled_types); + $language_settings + ->set('types', $enabled_types) + ->save(); } /** @@ -244,7 +247,9 @@ function language_types_set() { } // Save enabled language types. - variable_set('language_types', $language_types); + config('language.settings') + ->set('types', $language_types) + ->save(); // Ensure that subsequent calls of language_types_get_configurable() return // the updated language type information. diff --git a/core/includes/update.inc b/core/includes/update.inc index ec21aca..d61f818 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -197,20 +197,23 @@ function update_prepare_d8_bootstrap() { // process. drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); - // Update the 'language_default' system variable, if configured. + // Update the "language.settings.default" system variable, if configured. // Required to run before drupal_install_config_directories(), since that // triggers a call into system_stream_wrappers(), which calls t(), which // calls into language_default(). - $language_default = variable_get('language_default'); + $language_settings = config('language.detection'); + $language_default = $language_settings->get('default'); if (!empty($language_default) && (isset($language_default->langcode) || isset($language_default->language))) { if (!isset($language_default->langcode)) { $language_default->langcode = $language_default->language; } unset($language_default->language); - // In D8, the 'language_default' is not anymore an object, but an array, - // so make sure that the new value that is saved into this variable is an - // array. - variable_set('language_default', (array) $language_default); + // In D8, the "language.detection.default" variable is not anymore an + // object, but an array, so make sure that the new value that is saved + // into this variable is an array. + $language_settings + ->set('default', (array) $language_default) + ->save(); } $module_config = config('system.module'); @@ -351,7 +354,9 @@ function update_prepare_d8_language() { db_drop_field('languages', 'enabled'); // Update language count. - variable_set('language_count', db_query('SELECT COUNT(language) FROM {languages}')->fetchField()); + state('language.detection') + ->set('count', db_query('SELECT COUNT(language) FROM {languages}')->fetchField()) + ->save(); // Rename the languages table to language. db_rename_table('languages', 'language'); @@ -401,18 +406,22 @@ function update_prepare_d8_language() { } } - // Update the 'language_default' system variable with the langcode change. - $language_default = variable_get('language_default'); + // Update the language.detection.default system variable with the langcode + // change. + $language_settings = config('language.detection'); + $language_default = $language_settings->get('default'); if (!empty($language_default)) { if (isset($language_default->language)) { $language_default->langcode = $language_default->language; unset($language_default->language); } unset($language_default->enabled); - // In D8, the 'language_default' is not anymore an object, but an array, - // so make sure that the new value that is saved into this variable is an - // array. - variable_set('language_default', (array) $language_default); + // In D8, language.detection.default is not anymore an object, but an + // array, so make sure that the new value that is saved into this variable + // is an array. + $language_settings + ->set('default', (array) $language_default) + ->save(); } // Add column to track customized string status to locales_target. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index a704fb7..26c7ed6 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -56,7 +56,9 @@ function setUp() { $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type')); // Enable content language negotiation UI. - variable_set('language_test_content_language_type', TRUE); + config('language.test') + ->set('content_type', TRUE) + ->save(); // Set interface language detection to user and content language detection // to URL. Disable inheritance from interface language to ensure content diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index b2e4363..5e0a6fb 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -76,9 +76,10 @@ function field_language_insert() { field_info_cache_clear(); // If the number of languages is bigger than 1, enable the core language // fallback rules. - // Because the language_count is updated only after the hook is invoked, we - // check if the language_count is bigger or equal with 1 at the current time. - if (variable_get('language_count', 1) >= 1) { + // Because the "language.detection.count" variable is updated only after the + // hook is invoked, we check to see if it is bigger or equal with 1 at the + // current time. + if (state('language.detection')->get('count') >= 1) { variable_set('field_language_fallback', TRUE); } } @@ -97,9 +98,10 @@ function field_language_delete() { field_info_cache_clear(); // If the number of languages is less than 2, disable the core language // fallback rules. - // Because the language_count is updated after the hook is invoked, we check - // if the language_count is less or equal with 2 at the current time. - if (variable_get('language_count', 1) <= 2) { + // Because the "language.detection.count" variable is updated after the hook + // is invoked, we check to see if it is less than or equal with 2 at the + // current time. + if (state('language.detection')->get('count') <= 2) { variable_set('field_language_fallback', FALSE); } } diff --git a/core/modules/language/config/language.detection.yml b/core/modules/language/config/language.detection.yml index 1299603..9c9ec6d 100644 --- a/core/modules/language/config/language.detection.yml +++ b/core/modules/language/config/language.detection.yml @@ -1 +1,8 @@ selected_langcode: site_default +count: 1 +default: + 'langcode': 'en' + 'name': 'English' + 'direction': '0' + 'weight': '0' + 'locked': '0' diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index d51aa91..8926bd7 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -460,7 +460,7 @@ function language_negotiation_configure_form_table(&$form, $type) { $negotiation_info = $form['#language_negotiation_info']; $enabled_methods = variable_get("language_negotiation_$type", array()); - $methods_weight = variable_get("language_negotiation_methods_weight_$type", array()); + $methods_weight = config('lanuage.negotiation_methods')->get("weight_$type") ?: array(); // Add missing data to the methods lists. foreach ($negotiation_info as $method_id => $method) { @@ -618,7 +618,9 @@ function language_negotiation_configure_form_submit($form, &$form_state) { } language_negotiation_set($type, $method_weights); - variable_set("language_negotiation_methods_weight_$type", $method_weights_input); + config('language.negotiation_methods') + ->set("methods_weight_$type", $method_weights_input) + ->save(); } // Update non-configurable language types and the related language negotiation diff --git a/core/modules/language/language.install b/core/modules/language/language.install index b16c53b..36a7f23 100644 --- a/core/modules/language/language.install +++ b/core/modules/language/language.install @@ -31,20 +31,6 @@ function language_install() { * Implements hook_uninstall(). */ function language_uninstall() { - // Clear variables. - variable_del('language_default'); - variable_del('language_count'); - - // Clear variables. - variable_del('language_types'); - variable_del('language_content_type_default'); - variable_del('language_content_type_negotiation'); - - foreach (language_types_get_all() as $type) { - variable_del("language_negotiation_$type"); - variable_del("language_negotiation_methods_weight_$type"); - } - // Re-initialize the language system so successive calls to t() and other // functions will not expect languages to be present. drupal_language_initialize(); @@ -104,7 +90,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.detection.count" variable was forced to 1. language_update_count(); } @@ -112,8 +98,11 @@ function language_enable() { * Implements hook_disable(). */ function language_disable() { - // Force the language_count variable 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. - variable_set('language_count', 1); + // Force the "language.detection.count" variable 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. + state('language.detection') + ->set('count', '1') + ->save(); } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 71135a4..6b62bd5 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -476,7 +476,9 @@ function language_save($language) { if (!empty($language->default)) { // Set the new version of this language as default in a variable. $default_language = language_default(); - variable_set('language_default', (array) $language); + config('language.detection') + ->set('default', (array) $language) + ->save(); } // Update language count based on unlocked language count. @@ -493,14 +495,16 @@ function language_save($language) { } /** - * Updates the language_count variable. + * Updates the language.detection.count variable. * * This is used to check if a site is multilingual or not. * * @see language_multilingual() */ function language_update_count() { - variable_set('language_count', db_query('SELECT COUNT(langcode) FROM {language} WHERE locked = 0')->fetchField()); + state('language.detection') + ->set('count', db_query('SELECT COUNT(langcode) FROM {language} WHERE locked = 0')->fetchField()) + ->save(); } /** diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php index f72c51a..4eddc22 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php @@ -71,7 +71,9 @@ function testDependencyInjectedNewDefaultLanguage() { 'method_id' => 'language-default', 'default' => TRUE, ); - variable_set('language_default', $new_language_default); + config('language.detection') + ->set('default', $new_language_default) + ->save(); // Initialize the language system. drupal_language_initialize(); @@ -83,8 +85,5 @@ function testDependencyInjectedNewDefaultLanguage() { foreach ($expected as $property => $value) { $this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the default language object %prop property.', array('%prop' => $property))); } - - // Delete the language_default variable we previously set. - variable_del('language_default'); } } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php index 54a5f0e..dfa87a8 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php @@ -116,10 +116,11 @@ 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.settings.count" variable has been updated + // correctly. drupal_static_reset('language_list'); $languages = language_list(); - $this->assertEqual(variable_get('language_count', 1), count($languages), 'Language count is correct.'); + $this->assertEqual(state('language.detection')->get('count'), count($languages), 'Language count is correct.'); // Delete French. $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete')); // Get the count of languages. @@ -132,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. - $this->assertEqual(variable_get('language_count', 1), count($languages), 'Language count is correct.'); + // Make sure the "language.settings.count" variable has not changed. + $this->assertEqual(state('language.detection')->get('count'), count($languages), 'Language count is correct.'); // Ensure we can delete the English language. Right now English is the only // language so we must add a new language and make it the default before diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php index 961a556..705cc2a 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php @@ -42,8 +42,12 @@ function setUp() { */ function testInfoAlterations() { // Enable language type/negotiation info alterations. - variable_set('language_test_language_types', TRUE); - variable_set('language_test_language_negotiation_info', TRUE); + config('language.test') + ->set('types', TRUE) + ->save(); + config('language.test') + ->set('negotiation', TRUE) + ->save(); $this->languageNegotiationUpdate(); // Check that fixed language types are properly configured without the need @@ -52,10 +56,12 @@ function testInfoAlterations() { // Make the content language type configurable by updating the language // negotiation settings with the proper flag enabled. - variable_set('language_test_content_language_type', TRUE); + config('language.test') + ->set('content_type', TRUE) + ->save(); $this->languageNegotiationUpdate(); $type = LANGUAGE_TYPE_CONTENT; - $language_types = variable_get('language_types', language_types_get_default()); + $language_types = config('language.detection')->get('types') ?: language_types_get_default(); $this->assertTrue($language_types[$type], 'Content language type is configurable.'); // Enable some core and custom language negotiation methods. The test @@ -73,7 +79,9 @@ function testInfoAlterations() { // Remove the interface language negotiation method by updating the language // negotiation settings with the proper flag enabled. - variable_set('language_test_language_negotiation_info_alter', TRUE); + config('language.test') + ->set('negotiation_alter', TRUE) + ->save(); $this->languageNegotiationUpdate(); $negotiation = variable_get("language_negotiation_$type", array()); $this->assertFalse(isset($negotiation[$interface_method_id]), 'Interface language negotiation method removed from the stored settings.'); @@ -93,7 +101,7 @@ function testInfoAlterations() { // Check language negotiation results. $this->drupalGet(''); - $last = variable_get('language_test_language_negotiation_last', array()); + $last = config('language.test')->get('negotiation_last') ?: array(); foreach (language_types_get_all() as $type) { $langcode = $last[$type]; $value = $type == LANGUAGE_TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php index 66e7007..99e2614 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -103,11 +103,22 @@ function testUILanguageNegotiation() { // be some bug. drupal_static_reset('language_list'); $languages = language_list(); - variable_set('language_default', (array) $languages['vi']); + $language_settings = config('lanuage.detection'); + $language_settings + ->set('default', (array) $languages['vi']) + ->save(); // First visit this page to make sure our target string is searchable. $this->drupalGet('admin/config'); // Now the t()'ed string is in db so switch the language back to default. - variable_del('language_default'); + $language_settings + ->set('default', array( + 'langcode' => 'en', + 'name' => 'English', + 'direction' => 0, + 'weight' => 0, + 'locked' => 0 + )) + ->save(); // Translate the string. $language_browser_fallback_string = "In $langcode_browser_fallback In $langcode_browser_fallback In $langcode_browser_fallback"; @@ -382,7 +393,9 @@ protected function runTest($test) { ->save(); } if (!empty($test['language_test_domain'])) { - variable_set('language_test_domain', $test['language_test_domain']); + config('language.test') + ->set('domain', $test['language_test_domain']) + ->save(); } $this->drupalGet($test['path'], array(), $test['http_header']); $this->assertText($test['expect'], $test['message']); diff --git a/core/modules/language/tests/language_test.module b/core/modules/language/tests/language_test.module index be0a8c0..52dc927 100644 --- a/core/modules/language/tests/language_test.module +++ b/core/modules/language/tests/language_test.module @@ -12,7 +12,7 @@ * the HTTP_HOST here */ function language_test_boot() { - if (variable_get('language_test_domain')) { + if (config('language.test')->get('domain')) { $_SERVER['HTTP_HOST'] = variable_get('language_test_domain'); } } @@ -31,7 +31,7 @@ function language_test_init() { * Implements hook_language_types_info(). */ function language_test_language_types_info() { - if (variable_get('language_test_language_types', FALSE)) { + if (config('language.detection')->get('types')) { return array( 'test_language_type' => array( 'name' => t('Test'), @@ -48,7 +48,7 @@ function language_test_language_types_info() { * Implements hook_language_types_info_alter(). */ function language_test_language_types_info_alter(array &$language_types) { - if (variable_get('language_test_content_language_type', FALSE)) { + if (config('language.test')->get('content_type')) { unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']); } } @@ -57,7 +57,7 @@ function language_test_language_types_info_alter(array &$language_types) { * Implements hook_language_negotiation_info(). */ function language_test_language_negotiation_info() { - if (variable_get('language_test_language_negotiation_info', FALSE)) { + if (config('language.test')->get('negotiation_info')) { $info = array( 'callbacks' => array( 'negotiation' => 'language_test_language_negotiation_method', @@ -84,7 +84,7 @@ function language_test_language_negotiation_info() { * Implements hook_language_negotiation_info_alter(). */ function language_test_language_negotiation_info_alter(array &$negotiation_info) { - if (variable_get('language_test_language_negotiation_info_alter', FALSE)) { + if (config('language.test')->get('negotiation_alter')) { unset($negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE]); } } @@ -97,7 +97,9 @@ function language_test_store_language_negotiation() { foreach (language_types_get_all() as $type) { $last[$type] = language($type)->langcode; } - variable_set('language_test_language_negotiation_last', $last); + config('language.test') + ->set('negotiation_last', $last) + ->save(); } /** diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index 06583de..e47942c 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -87,7 +87,9 @@ function testUninstallProcess() { // Change language negotiation options. drupal_load('module', 'locale'); - variable_set('language_types', language_types_get_default() + array('language_custom' => TRUE)); + config('language.detection') + ->set('types', language_types_get_default() + array('language_custom' => TRUE)) + ->save(); variable_set('language_negotiation_' . LANGUAGE_TYPE_INTERFACE, language_language_negotiation_info()); variable_set('language_negotiation_' . LANGUAGE_TYPE_CONTENT, language_language_negotiation_info()); variable_set('language_negotiation_' . LANGUAGE_TYPE_URL, language_language_negotiation_info()); @@ -114,7 +116,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 = variable_get('language_count', 1); + $language_count = state('language.detection')->get('count'); $this->assertEqual($language_count, 1, t('Language count: %count', array('%count' => $language_count))); // Check language negotiation.