diff --git a/core/modules/language/config/language.negotiation.yml b/core/modules/language/config/language.negotiation.yml new file mode 100644 index 0000000..ed1c541 --- /dev/null +++ b/core/modules/language/config/language.negotiation.yml @@ -0,0 +1,2 @@ +session: + parameter: language diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index a601d00..b9ec2cb 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -797,16 +797,27 @@ function language_negotiation_configure_url_form_submit($form, &$form_state) { /** * Builds the session language negotiation method configuration form. + * + * @see language_negotiation_configure_session_form_submit() */ function language_negotiation_configure_session_form($form, &$form_state) { $form['language_negotiation_session_param'] = array( '#title' => t('Request/session parameter'), '#type' => 'textfield', - '#default_value' => variable_get('language_negotiation_session_param', 'language'), + '#default_value' => config('language.negotiation')->get('session.parameter'), '#description' => t('Name of the request/session parameter used to determine the desired language.'), ); $form_state['redirect'] = 'admin/config/regional/language/detection'; - return system_settings_form($form); + return system_config_form($form, $form_state); +} + +/** + * Form submission handler for language_negotiation_configure_session_form(). + */ +function language_negotiation_configure_session_form_submit($form, &$form_state) { + config('language.negotiation') + ->set('session.parameter', $form_state['values']['language_negotiation_session_param']) + ->save(); } diff --git a/core/modules/language/language.install b/core/modules/language/language.install index 37f41d6..8742492 100644 --- a/core/modules/language/language.install +++ b/core/modules/language/language.install @@ -40,7 +40,6 @@ function language_uninstall() { variable_del('language_negotiation_url_part'); variable_del('language_negotiation_url_prefixes'); variable_del('language_negotiation_url_domains'); - variable_del('language_negotiation_session_param'); variable_del('language_content_type_default'); variable_del('language_content_type_negotiation'); @@ -49,6 +48,8 @@ function language_uninstall() { variable_del("language_negotiation_methods_weight_$type"); } + config('language.negotiation')->delete('session.parameter')->save(); + // Re-initialize the language system so successive calls to t() and other // functions will not expect languages to be present. drupal_language_initialize(); @@ -102,3 +103,12 @@ function language_schema() { ); return $schema; } + +/** + * Moves language settings from variables to config. + */ +function language_update_8000() { + update_variables_to_config('language.negotiation', array( + 'language_negotiation_session_param' => 'session.parameter', + )); +} diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index 01c39a8..13a343d 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -171,7 +171,7 @@ function language_from_user($languages) { * A valid language code on success, FALSE otherwise. */ function language_from_session($languages) { - $param = variable_get('language_negotiation_session_param', 'language'); + $param = config('language.negotiation')->get('session.parameter'); // Request parameter: we need to update the session parameter only if we have // an authenticated user. @@ -320,7 +320,7 @@ function language_switcher_url($type, $path) { * Return the session language switcher block. */ function language_switcher_session($type, $path) { - $param = variable_get('language_negotiation_session_param', 'language'); + $param = config('language.negotiation')->get('session.parameter'); $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : drupal_container()->get($type)->langcode; $languages = language_list(); @@ -453,7 +453,7 @@ function language_url_rewrite_session(&$path, &$options) { global $user; if (!$user->uid) { $languages = language_list(); - $query_param = check_plain(variable_get('language_negotiation_session_param', 'language')); + $query_param = check_plain(config('language.negotiation')->get('session.parameter')); $query_value = isset($_GET[$query_param]) ? check_plain($_GET[$query_param]) : NULL; $query_rewrite = isset($languages[$query_value]) && language_negotiation_method_enabled(LANGUAGE_NEGOTIATION_SESSION); } diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index b63e8cd..9c45690 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -83,7 +83,7 @@ function testUninstallProcess() { // Change language negotiation settings. variable_set('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX); - variable_set('language_negotiation_session_param', TRUE); + config('language.negotiation')->set('session.parameter', TRUE)->save(); // Uninstall Locale. module_disable($locale_module); @@ -115,7 +115,7 @@ function testUninstallProcess() { // Check language negotiation method settings. $this->assertFalse(variable_get('language_negotiation_url_part', FALSE), t('URL language negotiation method indicator settings cleared.')); - $this->assertFalse(variable_get('language_negotiation_session_param', FALSE), t('Visit language negotiation method settings cleared.')); + $this->assertNull(config('language.negotiation')->get('session.parameter'), t('Visit language negotiation method settings cleared.')); // Check JavaScript parsed. $javascript_parsed_count = count(variable_get('javascript_parsed', array())); diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index 35106ae..31e30f4 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -554,11 +554,11 @@ function locale_update_8007() { * @ingroup config_upgrade */ function locale_update_8008() { + // @todo Convert other variables to configuration system too. $variable_name_map = array( 'locale_language_negotiation_url_part' => 'language_negotiation_url_part', 'locale_language_negotiation_url_domains' => 'language_negotiation_url_domains', 'locale_language_negotiation_url_prefixes' => 'language_negotiation_url_prefixes', - 'locale_language_negotiation_session_param' => 'language_negotiation_session_param', ); foreach ($variable_name_map as $deprecated_variable_name => $new_variable_name) { // Check if this variable is stored in the db and if so rename it. @@ -568,6 +568,10 @@ function locale_update_8008() { variable_del($deprecated_variable_name); } } + + update_variables_to_config('language.negotiation', array( + 'locale_language_negotiation_session_param' => 'session.parameter', + )); } /**