Commit 661488af authored by Dries's avatar Dries

- Patch #1222106 by Gábor Hojtsy, plach, xjm: Unify language negotiation APIs,...

- Patch #1222106 by Gábor Hojtsy, plach, xjm: Unify language negotiation APIs, declutter terminology.
parent cf77b6e8
This diff is collapsed.
......@@ -264,7 +264,7 @@ function locale_language_from_session($languages) {
function locale_language_from_url($languages) {
$language_url = FALSE;
if (!language_negotiation_get_any(LANGUAGE_NEGOTIATION_URL)) {
if (!language_negotiation_method_enabled(LANGUAGE_NEGOTIATION_URL)) {
return $language_url;
}
......@@ -303,8 +303,8 @@ function locale_language_from_url($languages) {
* Determines the language to be assigned to URLs when none is detected.
*
* The language negotiation process has a fallback chain that ends with the
* default language provider. Each built-in language type has a separate
* initialization:
* default language negotiation method. Each built-in language type has a
* separate initialization:
* - Interface language, which is the only configurable one, always gets a valid
* value. If no request-specific language is detected, the default language
* will be used.
......@@ -322,8 +322,8 @@ function locale_language_from_url($languages) {
*
* @param $languages
* (optional) An array of valid language objects. This is passed by
* language_provider_invoke() to every language provider callback, but it is
* not actually needed here. Defaults to NULL.
* language_negotiation_method_invoke() to every language method callback,
* but it is not actually needed here. Defaults to NULL.
* @param $language_type
* (optional) The language type to fall back to. Defaults to the interface
* language.
......@@ -406,7 +406,7 @@ function locale_language_switcher_session($type, $path) {
}
/**
* Rewrite URLs for the URL language provider.
* Rewrite URLs for the URL language negotiation method.
*/
function locale_language_url_rewrite_url(&$path, &$options) {
static $drupal_static_fast;
......@@ -492,7 +492,7 @@ function locale_language_negotiation_url_domains_save(array $domains) {
}
/**
* Rewrite URLs for the Session language provider.
* Rewrite URLs for the Session language negotiation method.
*/
function locale_language_url_rewrite_session(&$path, &$options) {
static $query_rewrite, $query_param, $query_value;
......@@ -506,16 +506,16 @@ function locale_language_url_rewrite_session(&$path, &$options) {
$languages = language_list(TRUE);
$query_param = check_plain(variable_get('locale_language_negotiation_session_param', 'language'));
$query_value = isset($_GET[$query_param]) ? check_plain($_GET[$query_param]) : NULL;
$query_rewrite = isset($languages[$query_value]) && language_negotiation_get_any(LANGUAGE_NEGOTIATION_SESSION);
$query_rewrite = isset($languages[$query_value]) && language_negotiation_method_enabled(LANGUAGE_NEGOTIATION_SESSION);
}
else {
$query_rewrite = FALSE;
}
}
// If the user is anonymous, the user language provider is enabled, and the
// corresponding option has been set, we must preserve any explicit user
// language preference even with cookies disabled.
// If the user is anonymous, the user language negotiation method is enabled,
// and the corresponding option has been set, we must preserve any explicit
// user language preference even with cookies disabled.
if ($query_rewrite) {
if (is_string($options['query'])) {
$options['query'] = drupal_get_query_array($options['query']);
......
......@@ -140,9 +140,9 @@ function update_prepare_stored_includes() {
// Update language negotiation settings.
foreach (language_types_get_all() as $language_type) {
$negotiation = variable_get("language_negotiation_$language_type", array());
foreach ($negotiation as $id => &$provider) {
if (isset($negotiation[$id]['file']) && $negotiation[$id]['file'] == 'includes/locale.inc') {
$negotiation[$id]['file'] = 'core/includes/locale.inc';
foreach ($negotiation as $method_id => &$method) {
if (isset($method['file']) && $method['file'] == 'includes/locale.inc') {
$method['file'] = 'core/includes/locale.inc';
}
}
variable_set("language_negotiation_$language_type", $negotiation);
......
......@@ -16,7 +16,7 @@ function language_negotiation_configure_form() {
'#theme' => 'language_negotiation_configure_form',
'#language_types' => language_types_get_configurable(FALSE),
'#language_types_info' => language_types_info(),
'#language_providers' => language_negotiation_info(),
'#language_negotiation_info' => language_negotiation_info(),
);
foreach ($form['#language_types'] as $type) {
......@@ -33,7 +33,7 @@ function language_negotiation_configure_form() {
}
/**
* Helper function to build a language provider table.
* Builds a language negotion method configuration table.
*/
function language_negotiation_configure_form_table(&$form, $type) {
$info = $form['#language_types_info'][$type];
......@@ -42,74 +42,74 @@ function language_negotiation_configure_form_table(&$form, $type) {
'#title' => t('@type language detection', array('@type' => $info['name'])),
'#tree' => TRUE,
'#description' => $info['description'],
'#language_providers' => array(),
'#language_negotiation_info' => array(),
'#show_operations' => FALSE,
'weight' => array('#tree' => TRUE),
'enabled' => array('#tree' => TRUE),
);
$language_providers = $form['#language_providers'];
$enabled_providers = variable_get("language_negotiation_$type", array());
$providers_weight = variable_get("locale_language_providers_weight_$type", array());
$negotiation_info = $form['#language_negotiation_info'];
$enabled_methods = variable_get("language_negotiation_$type", array());
$methods_weight = variable_get("locale_language_negotiation_methods_weight_$type", array());
// Add missing data to the providers lists.
foreach ($language_providers as $id => $provider) {
if (!isset($providers_weight[$id])) {
$providers_weight[$id] = language_provider_weight($provider);
// Add missing data to the methods lists.
foreach ($negotiation_info as $method_id => $method) {
if (!isset($methods_weight[$method_id])) {
$methods_weight[$method_id] = isset($method['weight']) ? $method['weight'] : 0;
}
}
// Order providers list by weight.
asort($providers_weight);
// Order methods list by weight.
asort($methods_weight);
foreach ($providers_weight as $id => $weight) {
// A language provider might be no more available if the defining module has
foreach ($methods_weight as $method_id => $weight) {
// A language method might be no more available if the defining module has
// been disabled after the last configuration saving.
if (!isset($language_providers[$id])) {
if (!isset($negotiation_info[$method_id])) {
continue;
}
$enabled = isset($enabled_providers[$id]);
$provider = $language_providers[$id];
$enabled = isset($enabled_methods[$method_id]);
$method = $negotiation_info[$method_id];
// List the provider only if the current type is defined in its 'types' key.
// List the method only if the current type is defined in its 'types' key.
// If it is not defined default to all the configurable language types.
$types = array_flip(isset($provider['types']) ? $provider['types'] : $form['#language_types']);
$types = array_flip(isset($method['types']) ? $method['types'] : $form['#language_types']);
if (isset($types[$type])) {
$table_form['#language_providers'][$id] = $provider;
$provider_name = check_plain($provider['name']);
$table_form['#language_negotiation_info'][$method_id] = $method;
$method_name = check_plain($method['name']);
$table_form['weight'][$id] = array(
$table_form['weight'][$method_id] = array(
'#type' => 'weight',
'#title' => t('Weight for !title language detection method', array('!title' => drupal_strtolower($provider_name))),
'#title' => t('Weight for !title language detection method', array('!title' => drupal_strtolower($method_name))),
'#title_display' => 'invisible',
'#default_value' => $weight,
'#attributes' => array('class' => array("language-provider-weight-$type")),
'#attributes' => array('class' => array("language-method-weight-$type")),
);
$table_form['title'][$id] = array('#markup' => $provider_name);
$table_form['title'][$method_id] = array('#markup' => $method_name);
$table_form['enabled'][$id] = array(
$table_form['enabled'][$method_id] = array(
'#type' => 'checkbox',
'#title' => t('Enable !title language detection method', array('!title' => drupal_strtolower($provider_name))),
'#title' => t('Enable !title language detection method', array('!title' => drupal_strtolower($method_name))),
'#title_display' => 'invisible',
'#default_value' => $enabled,
);
if ($id === LANGUAGE_NEGOTIATION_DEFAULT) {
$table_form['enabled'][$id]['#default_value'] = TRUE;
$table_form['enabled'][$id]['#attributes'] = array('disabled' => 'disabled');
if ($method_id === LANGUAGE_NEGOTIATION_DEFAULT) {
$table_form['enabled'][$method_id]['#default_value'] = TRUE;
$table_form['enabled'][$method_id]['#attributes'] = array('disabled' => 'disabled');
}
$table_form['description'][$id] = array('#markup' => filter_xss_admin($provider['description']));
$table_form['description'][$method_id] = array('#markup' => filter_xss_admin($method['description']));
$config_op = array();
if (isset($provider['config'])) {
$config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $provider['config']);
if (isset($method['config'])) {
$config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $method['config']);
// If there is at least one operation enabled show the operation column.
$table_form['#show_operations'] = TRUE;
}
$table_form['operation'][$id] = $config_op;
$table_form['operation'][$method_id] = $config_op;
}
}
......@@ -169,12 +169,12 @@ function theme_language_negotiation_configure_form($variables) {
$variables = array(
'header' => $header,
'rows' => $rows,
'attributes' => array('id' => "language-negotiation-providers-$type"),
'attributes' => array('id' => "language-negotiation-methods-$type"),
);
$table = theme('table', $variables);
$table .= drupal_render_children($form[$type]);
drupal_add_tabledrag("language-negotiation-providers-$type", 'order', 'sibling', "language-provider-weight-$type");
drupal_add_tabledrag("language-negotiation-methods-$type", 'order', 'sibling', "language-method-weight-$type");
$output .= '<div class="form-item">' . $title . $description . $table . '</div>';
}
......@@ -190,21 +190,19 @@ function language_negotiation_configure_form_submit($form, &$form_state) {
$configurable_types = $form['#language_types'];
foreach ($configurable_types as $type) {
$negotiation = array();
$enabled_providers = $form_state['values'][$type]['enabled'];
$enabled_providers[LANGUAGE_NEGOTIATION_DEFAULT] = TRUE;
$providers_weight = $form_state['values'][$type]['weight'];
foreach ($providers_weight as $id => $weight) {
if ($enabled_providers[$id]) {
$provider = $form[$type]['#language_providers'][$id];
$provider['weight'] = $weight;
$negotiation[$id] = $provider;
$method_weights = array();
$enabled_methods = $form_state['values'][$type]['enabled'];
$enabled_methods[LANGUAGE_NEGOTIATION_DEFAULT] = TRUE;
$method_weights_input = $form_state['values'][$type]['weight'];
foreach ($method_weights_input as $method_id => $weight) {
if ($enabled_methods[$method_id]) {
$method_weights[$method_id] = $weight;
}
}
language_negotiation_set($type, $negotiation);
variable_set("locale_language_providers_weight_$type", $providers_weight);
language_negotiation_set($type, $method_weights);
variable_set("locale_language_negotiation_methods_weight_$type", $method_weights_input);
}
// Update non-configurable language types and the related language negotiation
......@@ -216,7 +214,7 @@ function language_negotiation_configure_form_submit($form, &$form_state) {
}
/**
* Builds the URL language provider configuration form.
* Builds the URL language negotiation method configuration form.
*/
function language_negotiation_configure_url_form($form, &$form_state) {
$form['locale_language_negotiation_url_part'] = array(
......@@ -287,7 +285,7 @@ function language_negotiation_configure_url_form($form, &$form_state) {
}
/**
* Validation handler for url provider configuration.
* Validates the URL language negotiation method configuration.
*
* Validate that the prefixes and domains are unique, and make sure that
* the prefix and domain are only blank for the default.
......@@ -346,7 +344,7 @@ function language_negotiation_configure_url_form_validate($form, &$form_state) {
}
/**
* Save URL negotiation provider settings.
* Saves the URL language negotiation method settings.
*/
function language_negotiation_configure_url_form_submit($form, &$form_state) {
......@@ -361,7 +359,7 @@ function language_negotiation_configure_url_form_submit($form, &$form_state) {
}
/**
* The URL language provider configuration form.
* Builds the session language negotiation method configuration form.
*/
function language_negotiation_configure_session_form($form, &$form_state) {
$form['locale_language_negotiation_session_param'] = array(
......
......@@ -74,9 +74,9 @@ function hook_language_switch_links_alter(array &$links, $type, $path) {
* following key-value pairs:
* - "name": The human-readable language type identifier.
* - "description": A description of the language type.
* - "fixed": A fixed array of language provider identifiers to use to
* initialize this language. Defining this key makes the language type
* non-configurable and will always use the specified providers in the given
* - "fixed": A fixed array of language negotiation method identifiers to use
* to initialize this language. Defining this key makes the language type
* non-configurable and will always use the specified methods in the given
* priority order.
*/
function hook_language_types_info() {
......@@ -86,7 +86,7 @@ function hook_language_types_info() {
'description' => t('A custom language type.'),
),
'fixed_custom_language_type' => array(
'fixed' => array('custom_language_provider'),
'fixed' => array('custom_language_negotiation_method'),
),
);
}
......@@ -106,59 +106,59 @@ function hook_language_types_info_alter(array &$language_types) {
}
/**
* Allow modules to define their own language providers.
* Allow modules to define their own language negotiation methods.
*
* @return
* An array of language provider definitions. Each language provider has an
* identifier key. The language provider definition is an associative array
* that may contain the following key-value pairs:
* - "types": An array of allowed language types. If a language provider does
* not specify which language types it should be used with, it will be
* available for all the configurable language types.
* An array of language negotiation method definitions. Each method has an
* identifier key. The language negotiation method definition is an indexed
* array that may contain the following key-value pairs:
* - "types": An array of allowed language types. If a language negotiation
* method does not specify which language types it should be used with, it
* will be available for all the configurable language types.
* - "callbacks": An array of functions that will be called to perform various
* tasks. Possible key-value pairs are:
* - "language": Required. The callback that will determine the language
* - "negotiation": Required. The callback that will determine the language
* value.
* - "switcher": The callback that will determine the language switch links
* associated to the current language provider.
* - "language_switch": The callback that will determine the language
* switch links associated to the current language method.
* - "url_rewrite": The callback that will provide URL rewriting.
* - "file": A file that will be included before the callback is invoked; this
* allows callback functions to be in separate files.
* - "weight": The default weight the language provider has.
* - "weight": The default weight the language negotiation method has.
* - "name": A human-readable identifier.
* - "description": A description of the language provider.
* - "config": An internal path pointing to the language provider
* - "description": A description of the language negotiation method.
* - "config": An internal path pointing to the language negotiation method
* configuration page.
* - "cache": The value Drupal's page cache should be set to for the current
* language provider to be invoked.
* language negotiation method to be invoked.
*/
function hook_language_negotiation_info() {
return array(
'custom_language_provider' => array(
'custom_language_negotiation_method' => array(
'callbacks' => array(
'language' => 'custom_language_provider_callback',
'switcher' => 'custom_language_switcher_callback',
'url_rewrite' => 'custom_language_url_rewrite_callback',
'negotiation' => 'custom_negotiation_callback',
'language_switch' => 'custom_language_switch_callback',
'url_rewrite' => 'custom_url_rewrite_callback',
),
'file' => drupal_get_path('module', 'custom') . '/custom.module',
'weight' => -4,
'types' => array('custom_language_type'),
'name' => t('Custom language provider'),
'description' => t('This is a custom language provider.'),
'name' => t('Custom language negotiation method'),
'description' => t('This is a custom language negotiation method.'),
'cache' => 0,
),
);
}
/**
* Perform alterations on language providers.
* Perform alterations on language negotiation methods.
*
* @param $language_providers
* Array of language provider definitions.
* @param $negotiation_info
* Array of language negotiation method definitions.
*/
function hook_language_negotiation_info_alter(array &$language_providers) {
if (isset($language_providers['custom_language_provider'])) {
$language_providers['custom_language_provider']['config'] = 'admin/config/regional/language/detection/custom-language-provider';
function hook_language_negotiation_info_alter(array &$negotiation_info) {
if (isset($negotiation_info['custom_language_method'])) {
$negotiation_info['custom_language_method']['config'] = 'admin/config/regional/language/detection/custom-language-method';
}
}
......
......@@ -17,14 +17,14 @@ function locale_install() {
// We cannot rely on language negotiation hooks here, because locale module is
// not enabled yet. Therefore language_negotiation_set() cannot be used.
$info = locale_language_negotiation_info();
$provider = $info[LANGUAGE_NEGOTIATION_URL];
$provider_fields = array('callbacks', 'file', 'cache');
$method = $info[LANGUAGE_NEGOTIATION_URL];
$method_fields = array('callbacks', 'file', 'cache');
$negotiation = array();
// Store only the needed data.
foreach ($provider_fields as $field) {
if (isset($provider[$field])) {
$negotiation[LANGUAGE_NEGOTIATION_URL][$field] = $provider[$field];
foreach ($method_fields as $field) {
if (isset($method[$field])) {
$negotiation[LANGUAGE_NEGOTIATION_URL][$field] = $method[$field];
}
}
......@@ -99,7 +99,7 @@ function locale_uninstall() {
foreach (language_types_get_all() as $type) {
variable_del("language_negotiation_$type");
variable_del("locale_language_providers_weight_$type");
variable_del("locale_language_negotiation_methods_weight_$type");
}
// Remove all node type language variables. Node module might have been
......@@ -348,6 +348,37 @@ function locale_update_8003() {
}
}
/**
* Rename language providers to language negotiation methods.
*/
function locale_update_8004() {
$types = variable_get('language_types', NULL);
if (!empty($types)) {
foreach ($types as $type => $configurable) {
// Rename the negotiation and language switch callback keys.
$negotiation = variable_get('language_negotiation_' . $type, NULL);
if (!empty($negotiation)) {
foreach ($negotiation as $method_id => &$method) {
$method['callbacks']['negotiation'] = $method['callbacks']['language'];
unset($method['callbacks']['language']);
if (isset($method['callbacks']['switcher'])) {
$method['callbacks']['language_switch'] = $method['callbacks']['switcher'];
unset($method['callbacks']['switcher']);
}
}
variable_set('language_negotiation_' . $type, $negotiation);
}
// Rename the language negotiation methods weight variable.
$weight = variable_get('locale_language_providers_weight_' . $type , NULL);
if ($weight !== NULL) {
variable_set('locale_language_negotiation_methods_weight_' . $type , $weight);
variable_del('locale_language_providers_weight_' . $type);
}
}
}
}
/**
* @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000.
......
......@@ -230,7 +230,7 @@ function locale_language_selector_form($user) {
$names[$langcode] = $item->name;
}
// Get language negotiation settings.
$mode = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT;
$mode = language_negotiation_method_get_first(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_DEFAULT;
$form['locale'] = array(
'#type' => 'fieldset',
'#title' => t('Language settings'),
......@@ -414,8 +414,9 @@ function locale_entity_info_alter(&$entity_info) {
* language negotiated value. It is used by the Field API to determine the
* display language for fields if no explicit value is specified.
* - URL language is by default non-configurable and is determined through the
* URL language provider or the URL fallback provider if no language can be
* detected. It is used by l() as the default language if none is specified.
* URL language negotiation method or the URL fallback language negotiation
* method if no language can be detected. It is used by l() as the default
* language if none is specified.
*/
function locale_language_types_info() {
require_once DRUPAL_ROOT . '/core/includes/locale.inc';
......@@ -441,13 +442,13 @@ function locale_language_types_info() {
function locale_language_negotiation_info() {
require_once DRUPAL_ROOT . '/core/includes/locale.inc';
$file = '/core/includes/locale.inc';
$providers = array();
$negotiation_info = array();
$providers[LANGUAGE_NEGOTIATION_URL] = array(
$negotiation_info[LANGUAGE_NEGOTIATION_URL] = array(
'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL),
'callbacks' => array(
'language' => 'locale_language_from_url',
'switcher' => 'locale_language_switcher_url',
'negotiation' => 'locale_language_from_url',
'language_switch' => 'locale_language_switcher_url',
'url_rewrite' => 'locale_language_url_rewrite_url',
),
'file' => $file,
......@@ -457,10 +458,10 @@ function locale_language_negotiation_info() {
'config' => 'admin/config/regional/language/detection/url',
);
$providers[LANGUAGE_NEGOTIATION_SESSION] = array(
$negotiation_info[LANGUAGE_NEGOTIATION_SESSION] = array(
'callbacks' => array(
'language' => 'locale_language_from_session',
'switcher' => 'locale_language_switcher_session',
'negotiation' => 'locale_language_from_session',
'language_switch' => 'locale_language_switcher_session',
'url_rewrite' => 'locale_language_url_rewrite_session',
),
'file' => $file,
......@@ -470,16 +471,16 @@ function locale_language_negotiation_info() {
'config' => 'admin/config/regional/language/detection/session',
);
$providers[LANGUAGE_NEGOTIATION_USER] = array(
'callbacks' => array('language' => 'locale_language_from_user'),
$negotiation_info[LANGUAGE_NEGOTIATION_USER] = array(
'callbacks' => array('negotiation' => 'locale_language_from_user'),
'file' => $file,
'weight' => -4,
'name' => t('User'),
'description' => t("Follow the user's language preference."),
);
$providers[LANGUAGE_NEGOTIATION_BROWSER] = array(
'callbacks' => array('language' => 'locale_language_from_browser'),
$negotiation_info[LANGUAGE_NEGOTIATION_BROWSER] = array(
'callbacks' => array('negotiation' => 'locale_language_from_browser'),
'file' => $file,
'weight' => -2,
'cache' => 0,
......@@ -487,25 +488,25 @@ function locale_language_negotiation_info() {
'description' => t("Determine the language from the browser's language settings."),
);
$providers[LANGUAGE_NEGOTIATION_INTERFACE] = array(
$negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE] = array(
'types' => array(LANGUAGE_TYPE_CONTENT),
'callbacks' => array('language' => 'locale_language_from_interface'),
'callbacks' => array('negotiation' => 'locale_language_from_interface'),
'file' => $file,
'weight' => 8,
'name' => t('Interface'),
'description' => t('Use the detected interface language.'),
);
$providers[LANGUAGE_NEGOTIATION_URL_FALLBACK] = array(
$negotiation_info[LANGUAGE_NEGOTIATION_URL_FALLBACK] = array(
'types' => array(LANGUAGE_TYPE_URL),
'callbacks' => array('language' => 'locale_language_url_fallback'),
'callbacks' => array('negotiation' => 'locale_language_url_fallback'),
'file' => $file,
'weight' => 8,
'name' => t('URL fallback'),
'description' => t('Use an already detected language for URLs if none is found.'),
);
return $providers;
return $negotiation_info;
}
/**
......@@ -925,7 +926,7 @@ function locale_block_view($type) {
if (isset($links->links)) {
drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
$class = "language-switcher-{$links->provider}";
$class = "language-switcher-{$links->method_id}";
$variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
$block['content'] = theme('links__locale_block', $variables);
$block['subject'] = t('Languages');
......@@ -962,16 +963,16 @@ function locale_url_outbound_alter(&$path, &$options, $original_path) {
include_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach (language_types_get_configurable() as $type) {
// Get url rewriter callbacks only from enabled language providers.
// Get URL rewriter callbacks only from enabled language methods.
$negotiation = variable_get("language_negotiation_$type", array());
foreach ($negotiation as $id => $provider) {
if (isset($provider['callbacks']['url_rewrite'])) {
if (isset($provider['file'])) {
require_once DRUPAL_ROOT . '/' . $provider['file'];
foreach ($negotiation as $method_id => $method) {
if (isset($method['callbacks']['url_rewrite'])) {
if (isset($method['file'])) {
require_once DRUPAL_ROOT . '/' . $method['file'];
}
// Avoid duplicate callback entries.
$callbacks[$provider['callbacks']['url_rewrite']] = TRUE;
$callbacks[$method['callbacks']['url_rewrite']] = TRUE;
}
}
}
......
This diff is collapsed.
......@@ -22,8 +22,8 @@ function locale_test_boot() {
*/
function locale_test_init() {
locale_test_store_language_negotiation();
if (isset($GLOBALS['language_interface']) && isset($GLOBALS['language_interface']->provider)) {
drupal_set_message(t('Language negotiation provider: @name', array('@name' => $GLOBALS['language_interface']->provider)));
if (isset($GLOBALS['language_interface']) && isset($GLOBALS['language_interface']->method_id)) {
drupal_set_message(t('Language negotiation method: @name', array('@name' => $GLOBALS['language_interface']->method_id)));
}
}
......@@ -38,7 +38,7 @@ function locale_test_language_types_info() {
'description' => t('A test language type.'),
),
'fixed_test_language_type' => array(
'fixed' => array('test_language_provider'),
'fixed' => array('test_language_negotiation_method'),
),
);
}
......@@ -60,19 +60,19 @@ function locale_test_language_negotiation_info() {
if (variable_get('locale_test_language_negotiation_info', FALSE)) {
$info = array(
'callbacks' => array(
'language' => 'locale_test_language_provider',
'negotiation' => 'locale_test_language_negotiation_method',
),
'file' => drupal_get_path('module', 'locale_test') .'/locale_test.module',
'weight' => -10,
'description' => t('This is a test language provider.'),
'description' => t('This is a test language negotiation method.'),
);
return array(
'test_language_provider' => array(
'test_language_negotiation_method' => array(
'name' => t('Test'),
'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'),
) + $info,
'test_language_provider_ts' => array(
'test_language_negotiation_method_ts' => array(
'name' => t('Type-specific test'),
'types' => array('test_language_type'),
) + $info,
......@@ -83,9 +83,9 @@ function locale_test_language_negotiation_info() {
/**
* Implements hook_language_negotiation_info_alter().
*/
function locale_test_language_negotiation_info_alter(array &$language_providers) {
function locale_test_language_negotiation_info_alter(array &$negotiation_info) {
if (variable_get('locale_test_language_negotiation_info_alter', FALSE)) {
unset($language_providers[LANGUAGE_NEGOTIATION_INTERFACE]);
unset($negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE]);
}
}
......@@ -101,8 +101,8 @@ function locale_test_store_language_negotiation() {
}
/**
* Test language provider.
* Provides a test language negotiation method.
*/
function locale_test_language_provider($languages) {
function locale_test_language_negotiation_method($languages) {
return 'it';
}
......@@ -96,6 +96,14 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
// assigned LANGUAGE_NONE.
$file = db_query('SELECT * FROM {file_managed} WHERE fid = :fid', array(':fid' => 1))->fetchObject();
$this->assertEqual($file->langcode, LANGUAGE_NONE);
// Check if language negotiation weights were renamed properly. This is a
// reproduction of the previous weights from the dump.
$expected_weights = array('locale-url' => '-8', 'locale-session' => '-6', 'locale-user' => '-4', 'locale-browser' => '-2', 'language-default' => '10');
// Check that locale_language_providers_weight_language is correctly
// renamed.
$current_weights = variable_get('locale_language_negotiation_methods_weight_language_interface', array());
$this->assertTrue(serialize($expected_weights) == serialize($current_weights), t('Language negotiation method weights upgraded.'));
}
/**
......
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