Commit d5d172e3 authored by alexpott's avatar alexpott

Issue #1833022 by e0ipso, plach, YesCT, kfritsche, penyaskito, vijaycs85,...

Issue #1833022 by e0ipso, plach, YesCT, kfritsche, penyaskito, vijaycs85, nod_, cam8001: Only display interface language detection options to customize more granularity.
parent 3d521d93
...@@ -2409,8 +2409,10 @@ function language($type) { ...@@ -2409,8 +2409,10 @@ function language($type) {
* name and its value is its configurability (TRUE/FALSE). * name and its value is its configurability (TRUE/FALSE).
*/ */
function language_types_get_all() { function language_types_get_all() {
return array_keys(variable_get('language_types', language_types_get_default())); $types = \Drupal::config('system.language.types')->get('all');
return $types ? $types : array_keys(language_types_get_default());
} }
/** /**
* Returns a list of the built-in language types. * Returns a list of the built-in language types.
* *
......
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
*/ */
const LANGUAGE_NEGOTIATION_SELECTED = 'language-selected'; const LANGUAGE_NEGOTIATION_SELECTED = 'language-selected';
/**
* The language is determined using the current interface language.
*/
const LANGUAGE_NEGOTIATION_INTERFACE = 'language-interface';
/** /**
* @defgroup language_negotiation Language Negotiation API functionality * @defgroup language_negotiation Language Negotiation API functionality
* @{ * @{
...@@ -52,6 +57,10 @@ ...@@ -52,6 +57,10 @@
* } * }
* @endcode * @endcode
* *
* The locked configuration property prevents one language type from being
* switched from customized to not customized, and vice versa.
* @see language_types_set()
*
* Every language type can have a different set of language negotiation methods * Every language type can have a different set of language negotiation methods
* assigned to it. Different language types often share the same language * assigned to it. Different language types often share the same language
* negotiation settings, but they can have independent settings if needed. If * negotiation settings, but they can have independent settings if needed. If
...@@ -167,35 +176,12 @@ function language_types_info() { ...@@ -167,35 +176,12 @@ function language_types_info() {
* whose language negotiation methods are module-defined and not altered through * whose language negotiation methods are module-defined and not altered through
* the user interface. * 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
* alterations performed on the definitions by modules installed after the
* 'language_types' variable is set.
*
* @return * @return
* An array of language type names. * An array of language type names.
*/ */
function language_types_get_configurable($stored = TRUE) { function language_types_get_configurable() {
$configurable = &drupal_static(__FUNCTION__); $configurable = Drupal::config('system.language.types')->get('configurable');
return $configurable ? $configurable : array();
if ($stored && !isset($configurable)) {
$types = variable_get('language_types', language_types_get_default());
$configurable = array_keys(array_filter($types));
}
if (!$stored) {
$result = array();
foreach (language_types_info() as $type => $info) {
if (!isset($info['fixed'])) {
$result[] = $type;
}
}
return $result;
}
return $configurable;
} }
/** /**
...@@ -205,48 +191,70 @@ function language_types_get_configurable($stored = TRUE) { ...@@ -205,48 +191,70 @@ function language_types_get_configurable($stored = TRUE) {
* An array of language types. * An array of language types.
*/ */
function language_types_disable($types) { function language_types_disable($types) {
$enabled_types = variable_get('language_types', language_types_get_default()); $configurable = language_types_get_configurable();
config('system.language.types')->set('configurable', array_diff($configurable, $types))->save();
foreach ($types as $type) {
unset($enabled_types[$type]);
}
variable_set('language_types', $enabled_types);
} }
/** /**
* Updates the language type configuration. * Updates the language type configuration.
*
* @param array $configurable_language_types
* An array of configurable language types.
*/ */
function language_types_set() { function language_types_set(array $configurable_language_types) {
// Ensure that we are getting the defined language negotiation information. An // Ensure that we are getting the defined language negotiation information. An
// invocation of module_enable() or module_disable() could outdate the cached // invocation of module_enable() or module_disable() could outdate the cached
// information. // information.
drupal_static_reset('language_types_info'); drupal_static_reset('language_types_info');
drupal_static_reset('language_negotiation_info'); drupal_static_reset('language_negotiation_info');
// Determine which language types are configurable and which not by checking
// whether the 'fixed' key is defined. Non-configurable (fixed) language types
// have their language negotiation settings stored there.
$language_types = array(); $language_types = array();
$negotiation_info = language_negotiation_info(); $negotiation_info = language_negotiation_info();
foreach (language_types_info() as $type => $info) { $language_types_info = language_types_info();
if (isset($info['fixed'])) {
$language_types[$type] = FALSE; foreach ($language_types_info as $type => $info) {
$method_weights = array(); $configurable = in_array($type, $configurable_language_types);
foreach ($info['fixed'] as $weight => $method_id) {
if (isset($negotiation_info[$method_id])) { // Check whether the language type is unlocked. Only the status of unlocked
$method_weights[$method_id] = $weight; // language types can be toggled between configurable and non-configurable.
} // The default language negotiation settings, if available, are stored in
// $info['fixed'].
if (empty($info['locked'])) {
// If we have a non-locked non-configurable language type without default
// language negotiation settings, we use the values negotiated for the
// interface language which should always be available.
if (!$configurable && !empty($info['fixed'])) {
$method_weights = array(LANGUAGE_NEGOTIATION_INTERFACE);
$method_weights = array_flip($method_weights);
language_negotiation_set($type, $method_weights);
} }
language_negotiation_set($type, $method_weights);
} }
else { else {
$language_types[$type] = TRUE; // Locked language types with default settings are always considered
// non-configurable. In turn if default settings are missing, the language
// type is always considered configurable.
$configurable = empty($info['fixed']);
// If the language is non-configurable we need to store its language
// negotiation settings.
if (!$configurable) {
$method_weights = array();
foreach ($info['fixed'] as $weight => $method_id) {
if (isset($negotiation_info[$method_id])) {
$method_weights[$method_id] = $weight;
}
}
language_negotiation_set($type, $method_weights);
}
} }
$language_types[$type] = $configurable;
} }
// Save enabled language types. // Store the language type configuration.
variable_set('language_types', $language_types); $config = config('system.language.types');
$config->set('configurable', array_keys(array_filter($language_types)))->save();
$config->set('all', array_keys($language_types))->save();
// Ensure that subsequent calls of language_types_get_configurable() return // Ensure that subsequent calls of language_types_get_configurable() return
// the updated language type information. // the updated language type information.
...@@ -367,7 +375,7 @@ function language_negotiation_set($type, $method_weights) { ...@@ -367,7 +375,7 @@ function language_negotiation_set($type, $method_weights) {
$negotiation = array(); $negotiation = array();
$negotiation_info = language_negotiation_info(); $negotiation_info = language_negotiation_info();
$default_types = language_types_get_configurable(FALSE); $default_types = language_types_get_configurable();
// Order the language negotiation method list by weight. // Order the language negotiation method list by weight.
asort($method_weights); asort($method_weights);
......
...@@ -448,15 +448,20 @@ function update_prepare_d8_bootstrap() { ...@@ -448,15 +448,20 @@ function update_prepare_d8_bootstrap() {
* Fixes stored include paths to match the "/core" migration. * Fixes stored include paths to match the "/core" migration.
*/ */
function update_prepare_stored_includes() { function update_prepare_stored_includes() {
// Retrieve the currently stored language types. Default to the hardcoded D7
// values.
$default_language_types = array('language' => TRUE, 'language_content' => FALSE, 'language_url' => FALSE);
$language_types = array_keys(update_variable_get('language_types', $default_language_types));
// Update language negotiation settings. // Update language negotiation settings.
foreach (language_types_get_all() as $language_type) { foreach ($language_types as $language_type) {
$negotiation = variable_get("language_negotiation_$language_type", array()); $negotiation = update_variable_get("language_negotiation_$language_type", array());
foreach ($negotiation as &$method) { foreach ($negotiation as &$method) {
if (isset($method['file']) && $method['file'] == 'includes/locale.inc') { if (isset($method['file']) && $method['file'] == 'includes/locale.inc') {
$method['file'] = 'core/modules/language/language.negotiation.inc'; $method['file'] = 'core/modules/language/language.negotiation.inc';
} }
} }
variable_set("language_negotiation_$language_type", $negotiation); update_variable_set("language_negotiation_$language_type", $negotiation);
} }
} }
......
...@@ -146,7 +146,7 @@ public function isMultilingual() { ...@@ -146,7 +146,7 @@ public function isMultilingual() {
* An array of all language types. * An array of all language types.
*/ */
protected function getLanguageTypes() { protected function getLanguageTypes() {
return array_keys(variable_get('language_types', language_types_get_default())); return language_types_get_all();
} }
/** /**
......
...@@ -64,8 +64,9 @@ function content_translation_module_implements_alter(&$implementations, $hook) { ...@@ -64,8 +64,9 @@ function content_translation_module_implements_alter(&$implementations, $hook) {
* Implements hook_language_type_info_alter(). * Implements hook_language_type_info_alter().
*/ */
function content_translation_language_types_info_alter(array &$language_types) { function content_translation_language_types_info_alter(array &$language_types) {
// Make content language negotiation configurable by removing its predefined // Make content language negotiation configurable by removing the 'locked'
// configuration. // flag.
$language_types[Language::TYPE_CONTENT]['locked'] = FALSE;
unset($language_types[Language::TYPE_CONTENT]['fixed']); unset($language_types[Language::TYPE_CONTENT]['fixed']);
} }
......
...@@ -358,11 +358,17 @@ function language_negotiation_configure_form() { ...@@ -358,11 +358,17 @@ function language_negotiation_configure_form() {
$form = array( $form = array(
'#submit' => array('language_negotiation_configure_form_submit'), '#submit' => array('language_negotiation_configure_form_submit'),
'#theme' => 'language_negotiation_configure_form', '#theme' => 'language_negotiation_configure_form',
'#language_types' => language_types_get_configurable(FALSE),
'#language_types_info' => language_types_info(), '#language_types_info' => language_types_info(),
'#language_negotiation_info' => language_negotiation_info(), '#language_negotiation_info' => language_negotiation_info(),
); );
$form['#language_types'] = array();
$configurable = config('system.language.types')->get('configurable');
foreach ($form['#language_types_info'] as $type => $info) {
// Show locked language types only if they are configurable.
if (empty($info['locked']) || in_array($type, $configurable)) {
$form['#language_types'][] = $type;
}
}
foreach ($form['#language_types'] as $type) { foreach ($form['#language_types'] as $type) {
language_negotiation_configure_form_table($form, $type); language_negotiation_configure_form_table($form, $type);
} }
...@@ -390,6 +396,21 @@ function language_negotiation_configure_form_table(&$form, $type) { ...@@ -390,6 +396,21 @@ function language_negotiation_configure_form_table(&$form, $type) {
'#show_operations' => FALSE, '#show_operations' => FALSE,
'weight' => array('#tree' => TRUE), 'weight' => array('#tree' => TRUE),
); );
// Only show configurability checkbox for the unlocked language types.
if (empty($info['locked'])) {
$configurable = config('system.language.types')->get('configurable');
$table_form['configurable'] = array(
'#type' => 'checkbox',
'#title' => t('Customize %language_name language detection to differ from User interface text language detection settings.', array('%language_name' => $info['name'])),
'#default_value' => in_array($type, $configurable),
'#attributes' => array('class' => array('language-customization-checkbox')),
'#attached' => array(
'library' => array(
array('language', 'language.admin')
),
),
);
}
$negotiation_info = $form['#language_negotiation_info']; $negotiation_info = $form['#language_negotiation_info'];
$enabled_methods = variable_get("language_negotiation_$type", array()); $enabled_methods = variable_get("language_negotiation_$type", array());
...@@ -521,12 +542,13 @@ function theme_language_negotiation_configure_form($variables) { ...@@ -521,12 +542,13 @@ function theme_language_negotiation_configure_form($variables) {
'#rows' => $rows, '#rows' => $rows,
'#attributes' => array('id' => "language-negotiation-methods-$type"), '#attributes' => array('id' => "language-negotiation-methods-$type"),
); );
$table = drupal_render($build); $table = drupal_render($form[$type]['configurable']);
$table .= drupal_render($build);
$table .= drupal_render_children($form[$type]); $table .= drupal_render_children($form[$type]);
drupal_add_tabledrag("language-negotiation-methods-$type", 'order', 'sibling', "language-method-weight-$type"); drupal_add_tabledrag("language-negotiation-methods-$type", 'order', 'sibling', "language-method-weight-$type");
$output .= '<div class="form-item">' . $title . $description . $table . '</div>'; $output .= '<div class="form-item table-language-group table-' . $type . '-wrapper">' . $title . $description . $table . '</div>';
} }
$output .= drupal_render_children($form); $output .= drupal_render_children($form);
...@@ -539,11 +561,19 @@ function theme_language_negotiation_configure_form($variables) { ...@@ -539,11 +561,19 @@ function theme_language_negotiation_configure_form($variables) {
function language_negotiation_configure_form_submit($form, &$form_state) { function language_negotiation_configure_form_submit($form, &$form_state) {
$configurable_types = $form['#language_types']; $configurable_types = $form['#language_types'];
$stored_values = config('system.language.types')->get('configurable');
$customized = array();
$method_weights_type = array();
foreach ($configurable_types as $type) { foreach ($configurable_types as $type) {
$customized[$type] = in_array($type, $stored_values);
$method_weights = array(); $method_weights = array();
$enabled_methods = $form_state['values'][$type]['enabled']; $enabled_methods = $form_state['values'][$type]['enabled'];
$enabled_methods[LANGUAGE_NEGOTIATION_SELECTED] = TRUE; $enabled_methods[LANGUAGE_NEGOTIATION_SELECTED] = TRUE;
$method_weights_input = $form_state['values'][$type]['weight']; $method_weights_input = $form_state['values'][$type]['weight'];
if (isset($form_state['values'][$type]['configurable'])) {
$customized[$type] = !empty($form_state['values'][$type]['configurable']);
}
foreach ($method_weights_input as $method_id => $weight) { foreach ($method_weights_input as $method_id => $weight) {
if ($enabled_methods[$method_id]) { if ($enabled_methods[$method_id]) {
...@@ -551,13 +581,28 @@ function language_negotiation_configure_form_submit($form, &$form_state) { ...@@ -551,13 +581,28 @@ function language_negotiation_configure_form_submit($form, &$form_state) {
} }
} }
language_negotiation_set($type, $method_weights); $method_weights_type[$type] = $method_weights;
variable_set("language_negotiation_methods_weight_$type", $method_weights_input); variable_set("language_negotiation_methods_weight_$type", $method_weights_input);
} }
// Update non-configurable language types and the related language negotiation // Update non-configurable language types and the related language negotiation
// configuration. // configuration.
language_types_set(); language_types_set(array_keys(array_filter($customized)));
// Update the language negotiations after setting the configurability.
foreach ($method_weights_type as $type => $method_weights) {
language_negotiation_set($type, $method_weights);
}
// Clear block definitions cache since the available blocks and their names
// may have been changed based on the configurable types.
if (module_exists('block')) {
// If there is an active language switcher for a language type that has been
// made not configurable, deactivate it first.
$non_configurable = array_keys(array_diff($customized, array_filter($customized)));
_language_disable_language_switcher($non_configurable);
Drupal::service('plugin.manager.block')->clearCachedDefinitions();
}
$form_state['redirect'] = 'admin/config/regional/language/detection'; $form_state['redirect'] = 'admin/config/regional/language/detection';
drupal_set_message(t('Language negotiation configuration saved.')); drupal_set_message(t('Language negotiation configuration saved.'));
...@@ -582,10 +627,8 @@ function language_negotiation_configure_browser_form($form, &$form_state) { ...@@ -582,10 +627,8 @@ function language_negotiation_configure_browser_form($form, &$form_state) {
// the list of existing and then predefined languages. // the list of existing and then predefined languages.
if (empty($existing_languages)) { if (empty($existing_languages)) {
$language_options = language_admin_predefined_list(); $language_options = language_admin_predefined_list();
$default = key($language_options);
} }
else { else {
$default = key($existing_languages);
$language_options = array( $language_options = array(
t('Existing languages') => $existing_languages, t('Existing languages') => $existing_languages,
t('Languages not yet added') => language_admin_predefined_list() t('Languages not yet added') => language_admin_predefined_list()
...@@ -941,3 +984,21 @@ function language_content_settings_form_submit(array $form, array &$form_state) ...@@ -941,3 +984,21 @@ function language_content_settings_form_submit(array $form, array &$form_state)
} }
drupal_set_message(t('Settings successfully updated.')); drupal_set_message(t('Settings successfully updated.'));
} }
/**
* Helper function to disable the language switcher blocks.
*
* @param array $language_types
* Array containing all language types whose language switchers need to be
* disabled.
*/
function _language_disable_language_switcher(array $language_types) {
$blocks = _block_rehash();
foreach ($language_types as $language_type) {
foreach ($blocks as $block) {
if (strpos($block->id, 'language_switcher_' . substr($language_type, 9)) !== FALSE) {
$block->delete();
}
}
}
}
(function ($, Drupal) {
"use strict";
/**
* Makes language negotiation inherit user interface negotiation.
*/
Drupal.behaviors.negotiationLanguage = {
attach: function () {
var $configForm = $('#language-negotiation-configure-form');
var inputSelector = 'input[name$="[configurable]"]';
// Given a customization checkbox derive the language type being changed.
function toggleTable (checkbox) {
var $checkbox = $(checkbox);
// Get the language detection type such as User interface text language
// detection or Content language detection.
$checkbox.closest('.table-language-group')
.find('table, .tabledrag-toggle-weight')
.toggle($checkbox.prop('checked'));
}
// Bind hide/show and rearrange customization checkboxes.
$configForm.once('negotiation-language-admin-bind').on('change', inputSelector, function (event) {
toggleTable(event.target);
});
// Initially, hide language detection types that are not customized.
$configForm.find(inputSelector + ':not(:checked)').each(function (index, element) {
toggleTable(element);
});
}
};
})(jQuery, Drupal);
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
function language_install() { function language_install() {
// Enable URL language detection for each configurable language type. // Enable URL language detection for each configurable language type.
require_once DRUPAL_ROOT . '/core/includes/language.inc'; require_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach (language_types_get_configurable(FALSE) as $type) { foreach (language_types_get_configurable() as $type) {
module_load_include('inc', 'language', 'language.negotiation');
language_negotiation_set($type, array(LANGUAGE_NEGOTIATION_URL => 0)); language_negotiation_set($type, array(LANGUAGE_NEGOTIATION_URL => 0));
} }
} }
......
...@@ -590,6 +590,26 @@ function language_delete($langcode) { ...@@ -590,6 +590,26 @@ function language_delete($langcode) {
return FALSE; return FALSE;
} }
/**
* Implements hook_library_info().
*/
function language_library_info() {
$libraries['language.admin'] = array(
'title' => 'Language detection admin',
'version' => VERSION,
'js' => array(
drupal_get_path('module', 'language') . '/language.admin.js' => array(),
),
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
array('system', 'jquery.once'),
),
);
return $libraries;
}
/** /**
* Implements hook_language_types_info(). * Implements hook_language_types_info().
* *
...@@ -611,14 +631,17 @@ function language_language_types_info() { ...@@ -611,14 +631,17 @@ function language_language_types_info() {
Language::TYPE_INTERFACE => array( Language::TYPE_INTERFACE => array(
'name' => t('User interface text'), 'name' => t('User interface text'),
'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'), 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'),
'locked' => TRUE,
), ),
Language::TYPE_CONTENT => array( Language::TYPE_CONTENT => array(
'name' => t('Content'), 'name' => t('Content'),
'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'),
'fixed' => array(LANGUAGE_NEGOTIATION_INTERFACE), 'fixed' => array(LANGUAGE_NEGOTIATION_INTERFACE),
'locked' => TRUE,
), ),
Language::TYPE_URL => array( Language::TYPE_URL => array(
'fixed' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_URL_FALLBACK), 'fixed' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_URL_FALLBACK),
'locked' => TRUE,
), ),
); );
} }
...@@ -717,8 +740,9 @@ function language_negotiation_include() { ...@@ -717,8 +740,9 @@ function language_negotiation_include() {
* Implements hook_modules_enabled(). * Implements hook_modules_enabled().
*/ */
function language_modules_enabled($modules) { function language_modules_enabled($modules) {
language_negotiation_include(); include_once DRUPAL_ROOT . '/core/includes/language.inc';
language_types_set(); // Load configurability options from configuration.
language_types_set(array());
language_negotiation_purge(); language_negotiation_purge();
} }
......
...@@ -19,11 +19,6 @@ ...@@ -19,11 +19,6 @@
*/ */
const LANGUAGE_NEGOTIATION_BROWSER = 'language-browser'; const LANGUAGE_NEGOTIATION_BROWSER = 'language-browser';
/**
* The language is determined using the current interface language.
*/
const LANGUAGE_NEGOTIATION_INTERFACE = 'language-interface';
/** /**
* If no URL language, language is determined using an already detected one. * If no URL language, language is determined using an already detected one.
*/ */
......
...@@ -19,11 +19,17 @@ class LanguageBlock extends DerivativeBase { ...@@ -19,11 +19,17 @@ class LanguageBlock extends DerivativeBase {
public function getDerivativeDefinitions(array $base_plugin_definition) { public function getDerivativeDefinitions(array $base_plugin_definition) {
include_once DRUPAL_ROOT . '/core/includes/language.inc'; include_once DRUPAL_ROOT . '/core/includes/language.inc';
$info = language_types_info(); $info = language_types_info();
foreach (language_types_get_configurable(FALSE) as $type) { $configurable_types = language_types_get_configurable();
foreach ($configurable_types as $type) {
$this->derivatives[$type] = $base_plugin_definition; $this->derivatives[$type] = $base_plugin_definition;
$this->derivatives[$type]['admin_label'] = t('Language switcher (!type)', array('!type' => $info[$type]['name'])); $this->derivatives[$type]['admin_label'] = t('Language switcher (!type)', array('!type' => $info[$type]['name']));
$this->derivatives[$type]['cache'] = DRUPAL_NO_CACHE; $this->derivatives[$type]['cache'] = DRUPAL_NO_CACHE;
} }
// If there is just one configurable type then change the title of the
// block.
if (count($configurable_types) == 1) {
$this->derivatives[reset($configurable_types)]['admin_label'] = t('Language switcher');
}
return parent::getDerivativeDefinitions($base_plugin_definition); return parent::getDerivativeDefinitions($base_plugin_definition);
} }
} }
...@@ -56,8 +56,8 @@ function testInfoAlterations() { ...@@ -56,8 +56,8 @@ function testInfoAlterations() {
\Drupal::state()->set('language_test.content_language_type', TRUE); \Drupal::state()->set('language_test.content_language_type', TRUE);
$this->languageNegotiationUpdate(); $this->languageNegotiationUpdate();
$type = Language::TYPE_CONTENT; $type = Language::TYPE_CONTENT;
$language_types = variable_get('language_types', language_types_get_default()); $language_types = language_types_get_configurable();
$this->assertTrue($language_types[$type], 'Content language type is configurable.'); $this->assertTrue(in_array($type, $language_types), 'Content language type is configurable.');
// Enable some core and custom language negotiation methods. The test // Enable some core and custom language negotiation methods. The test
// language type is supposed to be configurable. // language type is supposed to be configurable.
...@@ -69,6 +69,7 @@ function testInfoAlterations() { ...@@ -69,6 +69,7 @@ function testInfoAlterations() {
$form_field => TRUE, $form_field => TRUE,
$type . '[enabled][' . $test_method_id . ']' => TRUE, $type . '[enabled][' . $test_method_id . ']' => TRUE,
$test_type . '[enabled][' . $test_method_id . ']' => TRUE, $test_type . '[enabled][' . $test_method_id . ']' => TRUE,
$test_type . '[configurable]' => TRUE,
); );
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings')); $this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
...@@ -98,7 +99,7 @@ function testInfoAlterations() { ...@@ -98,7 +99,7 @@ function testInfoAlterations() {
foreach (language_types_get_all() as $type) { foreach (language_types_get_all() as $type) {
$langcode = $last[$type]; $langcode = $last[$type];
$value = $type == Language::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; $value = $type == Language::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en';
$this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type, '%language' => $langcode))); $this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type, '%language' => $value)));
} }
// Disable language_test and check that everything is set back to the // Disable language_test and check that everything is set back to the
...@@ -158,8 +159,9 @@ protected function languageNegotiationUpdate($op = 'enable') { ...@@ -158,8 +159,9 @@ protected function languageNegotiationUpdate($op = 'enable') {
*/ */
protected function checkFixedLanguageTypes() { protected function checkFixedLanguageTypes() {
drupal_static_reset('language_types_info'); drupal_static_reset('language_types_info');
$configurable = language_types_get_configurable();
foreach (language_types_info() as $type => $info) { foreach (language_types_info() as $type => $info) {
if (isset($info['fixed'])) { if (!in_array($type, $configurable) && isset($info['fixed'])) {
$negotiation = variable_get("language_negotiation_$type", array()); $negotiation = variable_get("language_negotiation_$type", array());
$equal = count($info['fixed']) == count($negotiation); $equal = count($info['fixed']) == count($negotiation);
while ($equal && list($id) = each($negotiation)) { while ($equal && list($id) = each($negotiation)) {
......
...@@ -32,6 +32,7 @@ function language_test_language_types_info() { ...@@ -32,6 +32,7 @@ function language_test_language_types_info() {
), ),
'fixed_test_language_type' => array( 'fixed_test_language_type' => array(
'fixed' => array('test_language_negotiation_method'), 'fixed' => array('test_language_negotiation_method'),
'locked' => TRUE,
), ),
); );
} }
...@@ -42,7 +43,15 @@ function language_test_language_types_info() { ...@@ -42,7 +43,15 @@ function language_test_language_types_info() {
*/ */
function language_test_language_types_info_alter(array &$language_types) { function language_test_language_types_info_alter(array &$language_types) {
if (Drupal::state()->get('language_test.content_language_type')) { if (Drupal::state()->get('language_test.content_languag