Commit 8deaba40 authored by webchick's avatar webchick

Issue #1714462 by n3or, sun, Gábor Hojtsy: Convert language negotiation...

Issue #1714462 by n3or, sun, Gábor Hojtsy: Convert language negotiation settings to configuration system.
parent 8f7d8e96
session:
parameter: language
url:
source: path_prefix
prefixes:
en: ''
domains:
en: ''
......@@ -631,6 +631,9 @@ function language_negotiation_configure_form_submit($form, &$form_state) {
/**
* Builds the URL language negotiation method configuration form.
*
* @see language_negotiation_configure_url_form_validate()
* @see language_negotiation_configure_url_form_submit()
*/
function language_negotiation_configure_url_form($form, &$form_state) {
global $base_url;
......@@ -643,7 +646,7 @@ function language_negotiation_configure_url_form($form, &$form_state) {
LANGUAGE_NEGOTIATION_URL_PREFIX => t('Path prefix'),
LANGUAGE_NEGOTIATION_URL_DOMAIN => t('Domain'),
),
'#default_value' => variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX),
'#default_value' => config('language.negotiation')->get('url.source'),
);
$form['prefix'] = array(
......@@ -695,12 +698,7 @@ function language_negotiation_configure_url_form($form, &$form_state) {
$form_state['redirect'] = 'admin/config/regional/language/detection';
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
return $form;
return system_config_form($form, $form_state);
}
/**
......@@ -769,33 +767,44 @@ function language_negotiation_configure_url_form_validate($form, &$form_state) {
}
/**
* Saves the URL language negotiation method settings.
* Form submission handler for language_negotiation_configure_url_form().
*/
function language_negotiation_configure_url_form_submit($form, &$form_state) {
// Save selected format (prefix or domain).
variable_set('language_negotiation_url_part', $form_state['values']['language_negotiation_url_part']);
config('language.negotiation')
->set('url.source', $form_state['values']['language_negotiation_url_part'])
->save();
// Save new domain and prefix values.
language_negotiation_url_prefixes_save($form_state['values']['prefix']);
language_negotiation_url_domains_save($form_state['values']['domain']);
drupal_set_message(t('Configuration saved.'));
}
/**
* 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();
}
/**
......
......@@ -37,10 +37,6 @@ function language_uninstall() {
// Clear variables.
variable_del('language_types');
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');
......
......@@ -43,12 +43,12 @@
/**
* URL language negotiation: use the path prefix as URL language indicator.
*/
const LANGUAGE_NEGOTIATION_URL_PREFIX = 0;
const LANGUAGE_NEGOTIATION_URL_PREFIX = 'path_prefix';
/**
* URL language negotiation: use the domain as URL language indicator.
*/
const LANGUAGE_NEGOTIATION_URL_DOMAIN = 1;
const LANGUAGE_NEGOTIATION_URL_DOMAIN = 'domain';
/**
* Identifies the language from the current interface language.
......@@ -231,7 +231,7 @@ function language_from_user_admin($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.
......@@ -270,7 +270,7 @@ function language_from_url($languages, $request) {
return $language_url;
}
switch (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX)) {
switch (config('language.negotiation')->get('url.source')) {
case LANGUAGE_NEGOTIATION_URL_PREFIX:
$current_path = $request->attributes->get('system_path');
......@@ -353,7 +353,7 @@ function language_from_url($languages, $request) {
*/
function language_url_fallback($language = NULL, $request = NULL, $language_type = LANGUAGE_TYPE_INTERFACE) {
$default = language_default();
$prefix = (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX) == LANGUAGE_NEGOTIATION_URL_PREFIX);
$prefix = (config('language.negotiation')->get('url.source') == LANGUAGE_NEGOTIATION_URL_PREFIX);
// If the default language is not configured to convey language information,
// a missing URL language information indicates that URL language should be
......@@ -394,7 +394,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] : language($type)->langcode;
$languages = language_list();
......@@ -448,7 +448,7 @@ function language_url_rewrite_url(&$path, &$options) {
}
if (isset($options['language'])) {
switch (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX)) {
switch (config('language.negotiation')->get('url.source')) {
case LANGUAGE_NEGOTIATION_URL_DOMAIN:
$domains = language_negotiation_url_domains();
if (is_object($options['language']) && !empty($domains[$options['language']->langcode])) {
......@@ -504,7 +504,7 @@ function language_url_rewrite_url(&$path, &$options) {
* Reads language prefixes and uses the langcode if no prefix is set.
*/
function language_negotiation_url_prefixes() {
return variable_get('language_negotiation_url_prefixes', array());
return config('language.negotiation')->get('url.prefixes');
}
/**
......@@ -529,21 +529,25 @@ function language_negotiation_url_prefixes_update() {
* Saves language prefix settings.
*/
function language_negotiation_url_prefixes_save(array $prefixes) {
variable_set('language_negotiation_url_prefixes', $prefixes);
config('language.negotiation')
->set('url.prefixes', $prefixes)
->save();
}
/**
* Reads language domains.
*/
function language_negotiation_url_domains() {
return variable_get('language_negotiation_url_domains', array());
return config('language.negotiation')->get('url.domains');
}
/**
* Saves the language domain settings.
*/
function language_negotiation_url_domains_save(array $domains) {
variable_set('language_negotiation_url_domains', $domains);
config('language.negotiation')
->set('url.domains', $domains)
->save();
}
/**
......@@ -558,7 +562,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);
}
......
......@@ -377,7 +377,9 @@ protected function runTest($test) {
language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $method_weights);
}
if (!empty($test['language_negotiation_url_part'])) {
variable_set('language_negotiation_url_part', $test['language_negotiation_url_part']);
config('language.negotiation')
->set('url.source', $test['language_negotiation_url_part'])
->save();
}
if (!empty($test['language_test_domain'])) {
variable_set('language_test_domain', $test['language_test_domain']);
......@@ -456,7 +458,7 @@ function testLanguageDomain() {
// Change the domain for the Italian language.
$edit = array(
'language_negotiation_url_part' => 1,
'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
'domain[it]' => 'it.example.com',
);
$this->drupalPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
......
......@@ -101,13 +101,15 @@ private function checkUrl($language, $message1, $message2) {
function testDomainNameNegotiationPort() {
$language_domain = 'example.fr';
$edit = array(
'language_negotiation_url_part' => 1,
'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
'domain[fr]' => $language_domain
);
$this->drupalPost('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
// Enable domain configuration.
variable_set('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_DOMAIN);
config('language.negotiation')
->set('url.source', LANGUAGE_NEGOTIATION_URL_DOMAIN)
->save();
// Reset static caching.
drupal_static_reset('language_list');
......
......@@ -93,8 +93,10 @@ function testUninstallProcess() {
variable_set('language_negotiation_' . LANGUAGE_TYPE_URL, language_language_negotiation_info());
// 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('url.source', LANGUAGE_NEGOTIATION_URL_PREFIX)
->set('session.parameter', TRUE)
->save();
// Uninstall Locale.
module_disable($locale_module);
......@@ -126,8 +128,8 @@ function testUninstallProcess() {
$this->assertTrue($language_negotiation, t('URL language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
// 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->assertFalse(config('language.negotiation')->get('url.source'), t('URL language negotiation method indicator settings cleared.'));
$this->assertFalse(config('language.negotiation')->get('session.parameter'), t('Visit language negotiation method settings cleared.'));
// Check JavaScript parsed.
$javascript_parsed_count = count(state()->get('system.javascript_parsed') ?: array());
......
......@@ -649,6 +649,12 @@ function locale_update_8008() {
update_variable_del($deprecated_variable_name);
}
}
update_variables_to_config('language.negotiation', array(
'locale_language_negotiation_session_param' => 'session.parameter',
'language_negotiation_url_part' => 'url.source',
'language_negotiation_url_prefixes' => 'url.prefixes',
'language_negotiation_url_domains' => 'url.domains',
));
}
/**
......
......@@ -696,7 +696,7 @@ function overlay_overlay_parent_initialize() {
$path_prefixes = array();
if (module_exists('language')) {
language_negotiation_include();
if (variable_get('language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX) == LANGUAGE_NEGOTIATION_URL_PREFIX) {
if (config('language.negotiation')->get('url.source') == LANGUAGE_NEGOTIATION_URL_PREFIX) {
// Skip the empty string indicating the default language. We always accept
// paths without a prefix.
$path_prefixes = language_negotiation_url_prefixes();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment