diff --git a/core/includes/language.inc b/core/includes/language.inc
index f12f34a..169fef8 100644
--- a/core/includes/language.inc
+++ b/core/includes/language.inc
@@ -20,22 +20,22 @@ const LANGUAGE_NEGOTIATION_DEFAULT = 'language-default';
* The negotiated language object.
*/
function language_types_initialize($type) {
- // Execute the language providers in the order they were set up and return the
- // first valid language found.
+ // Execute the language negotiation methods in the order they were set up and
+ // return the first valid language found.
$negotiation = variable_get("language_negotiation_$type", array());
- foreach ($negotiation as $provider_id => $provider) {
- $language = language_provider_invoke($provider_id, $provider);
+ foreach ($negotiation as $method_id => $method) {
+ $language = language_negotiation_method_invoke($method_id, $method);
if ($language) {
- // Remember the provider key used to detect the language.
- $language->provider = $provider_id;
+ // Remember the method id used to detect the language.
+ $language->method_id = $method_id;
return $language;
}
}
// If no other language was found use the default one.
$language = language_default();
- $language->provider = LANGUAGE_NEGOTIATION_DEFAULT;
+ $language->method_id = LANGUAGE_NEGOTIATION_DEFAULT;
return $language;
}
@@ -68,8 +68,8 @@ function language_types_info() {
* language type itself.
*
* @param $stored
- * Optional. By default retrieves values from the 'language_types' variable to
- * avoid unnecessary hook invocations.
+ * (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 to react to alterations performed on the definitions by modules
* installed after the 'language_types' variable is set.
@@ -99,7 +99,7 @@ function language_types_get_configurable($stored = TRUE) {
}
/**
- * Disable the given language types.
+ * Disables the given language types.
*
* @param $types
* An array of language types.
@@ -128,17 +128,17 @@ function language_types_set() {
// whether the 'fixed' key is defined. Non-configurable (fixed) language types
// have their language negotiation settings stored there.
$language_types = array();
- $defined_providers = language_negotiation_info();
+ $negotiation_info = language_negotiation_info();
foreach (language_types_info() as $type => $info) {
if (isset($info['fixed'])) {
$language_types[$type] = FALSE;
- $negotiation = array();
- foreach ($info['fixed'] as $weight => $id) {
- if (isset($defined_providers[$id])) {
- $negotiation[$id] = $weight;
+ $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, $negotiation);
+ language_negotiation_set($type, $method_weights);
}
else {
$language_types[$type] = TRUE;
@@ -154,52 +154,35 @@ function language_types_set() {
}
/**
- * Check if a language provider is enabled.
- *
- * This has two possible behaviors:
- * - If $provider_id is given return its ID if enabled, FALSE otherwise.
- * - If no ID is passed the first enabled language provider is returned.
+ * Returns the ID of the first language negotiation method for the language type.
*
* @param $type
- * The language negotiation type.
- * @param $provider_id
- * The language provider ID.
- *
- * @return
- * The provider ID if it is enabled, FALSE otherwise.
+ * The language type.
*/
-function language_negotiation_get($type, $provider_id = NULL) {
+function language_negotiation_method_get_first($type) {
$negotiation = variable_get("language_negotiation_$type", array());
-
- if (empty($negotiation)) {
- return empty($provider_id) ? LANGUAGE_NEGOTIATION_DEFAULT : FALSE;
- }
-
- if (empty($provider_id)) {
- return key($negotiation);
- }
-
- if (isset($negotiation[$provider_id])) {
- return $provider_id;
- }
-
- return FALSE;
+ return empty($negotiation) ? LANGUAGE_NEGOTIATION_DEFAULT : key($negotiation);
}
/**
- * Check if the given language provider is enabled for any configurable language
- * type.
+ * Checks if a language negotiation method is enabled for a language type.
*
- * @param $provider_id
- * The language provider ID.
+ * @param $method_id
+ * The language negotiation method ID.
+ * @param $type
+ * (optional) The language type. If none is passed all the configurable
+ * language types will be inspected.
*
* @return
- * TRUE if there is at least one language type for which the give language
- * provider is enabled, FALSE otherwise.
+ * TRUE if the method is enabled for at least one of the given language types,
+ * FALSE otherwise.
*/
-function language_negotiation_get_any($provider_id) {
- foreach (language_types_get_configurable() as $type) {
- if (language_negotiation_get($type, $provider_id)) {
+function language_negotiation_method_enabled($method_id, $type = NULL) {
+ $language_types = !empty($type) ? array($type) : language_types_get_configurable();
+
+ foreach ($language_types as $type) {
+ $negotiation = variable_get("language_negotiation_$type", array());
+ if (isset($negotiation[$method_id])) {
return TRUE;
}
}
@@ -208,10 +191,10 @@ function language_negotiation_get_any($provider_id) {
}
/**
- * Return the language switch links for the given language.
+ * Returns the language switch links for the given language type.
*
* @param $type
- * The language negotiation type.
+ * The language type.
* @param $path
* The internal path the switch links will be relative to.
*
@@ -222,19 +205,19 @@ function language_negotiation_get_switch_links($type, $path) {
$links = FALSE;
$negotiation = variable_get("language_negotiation_$type", array());
- foreach ($negotiation as $id => $provider) {
- if (isset($provider['callbacks']['switcher'])) {
- if (isset($provider['file'])) {
- require_once DRUPAL_ROOT . '/' . $provider['file'];
+ foreach ($negotiation as $method_id => $method) {
+ if (isset($method['callbacks']['language_switch'])) {
+ if (isset($method['file'])) {
+ require_once DRUPAL_ROOT . '/' . $method['file'];
}
- $callback = $provider['callbacks']['switcher'];
+ $callback = $method['callbacks']['language_switch'];
$result = $callback($type, $path);
if (!empty($result)) {
// Allow modules to provide translations for specific links.
drupal_alter('language_switch_links', $result, $type, $path);
- $links = (object) array('links' => $result, 'provider' => $id);
+ $links = (object) array('links' => $result, 'method_id' => $method_id);
break;
}
}
@@ -244,7 +227,7 @@ function language_negotiation_get_switch_links($type, $path) {
}
/**
- * Updates language configuration to remove any language provider that is no longer defined.
+ * Removes any language negotiation methods that are no longer defined.
*/
function language_negotiation_purge() {
// Ensure that we are getting the defined language negotiation information. An
@@ -253,60 +236,54 @@ function language_negotiation_purge() {
drupal_static_reset('language_negotiation_info');
drupal_static_reset('language_types_info');
- $defined_providers = language_negotiation_info();
+ $negotiation_info = language_negotiation_info();
foreach (language_types_info() as $type => $type_info) {
$weight = 0;
- $negotiation = array();
- foreach (variable_get("language_negotiation_$type", array()) as $id => $provider) {
- if (isset($defined_providers[$id])) {
- $negotiation[$id] = $weight++;
+ $method_weights = array();
+ foreach (variable_get("language_negotiation_$type", array()) as $method_id => $method) {
+ if (isset($negotiation_info[$method_id])) {
+ $method_weights[$method_id] = $weight++;
}
}
- language_negotiation_set($type, $negotiation);
+ language_negotiation_set($type, $method_weights);
}
}
/**
- * Save a list of language providers.
+ * Saves a list of language negotiation methods for a language type.
*
* @param $type
- * The language negotiation type.
- * @param $language_providers
- * An array of language provider weights keyed by id.
- * @see language_provider_weight()
+ * The language type.
+ * @param $method_weights
+ * An array of language negotiation method weights keyed by method id.
*/
-function language_negotiation_set($type, $language_providers) {
+function language_negotiation_set($type, $method_weights) {
// Save only the necessary fields.
- $provider_fields = array('callbacks', 'file', 'cache');
+ $method_fields = array('callbacks', 'file', 'cache');
$negotiation = array();
- $providers_weight = array();
- $defined_providers = language_negotiation_info();
+ $negotiation_info = language_negotiation_info();
$default_types = language_types_get_configurable(FALSE);
- // Initialize the providers weight list.
- foreach ($language_providers as $id => $provider) {
- $providers_weight[$id] = language_provider_weight($provider);
- }
-
- // Order providers list by weight.
- asort($providers_weight);
-
- foreach ($providers_weight as $id => $weight) {
- if (isset($defined_providers[$id])) {
- $provider = $defined_providers[$id];
- // If the provider does not express any preference about types, make it
- // available for any configurable type.
- $types = array_flip(isset($provider['types']) ? $provider['types'] : $default_types);
- // Check if the provider is defined and has the right type.
+ // Order the language negotiation method list by weight.
+ asort($method_weights);
+
+ foreach ($method_weights as $method_id => $weight) {
+ if (isset($negotiation_info[$method_id])) {
+ $method = $negotiation_info[$method_id];
+ // If the language negotiation method does not express any preference
+ // about types, make it available for any configurable type.
+ $types = array_flip(isset($method['types']) ? $method['types'] : $default_types);
+ // Check if the language negotiation method is defined and has the right
+ // type.
if (isset($types[$type])) {
- $provider_data = array();
- foreach ($provider_fields as $field) {
- if (isset($provider[$field])) {
- $provider_data[$field] = $provider[$field];
+ $method_data = array();
+ foreach ($method_fields as $field) {
+ if (isset($method[$field])) {
+ $method_data[$field] = $method[$field];
}
}
- $negotiation[$id] = $provider_data;
+ $negotiation[$method_id] = $method_data;
}
}
}
@@ -315,20 +292,20 @@ function language_negotiation_set($type, $language_providers) {
}
/**
- * Return all the defined language providers.
+ * Returns all defined language negotiation methods.
*
* @return
- * An array of language providers.
+ * An array of language negotiation methods.
*/
function language_negotiation_info() {
- $language_providers = &drupal_static(__FUNCTION__);
+ $negotiation_info = &drupal_static(__FUNCTION__);
- if (!isset($language_providers)) {
- // Collect all the module-defined language negotiation providers.
- $language_providers = module_invoke_all('language_negotiation_info');
+ if (!isset($negotiation_info)) {
+ // Collect all the module-defined language negotiation methods.
+ $negotiation_info = module_invoke_all('language_negotiation_info');
- // Add the default language provider.
- $language_providers[LANGUAGE_NEGOTIATION_DEFAULT] = array(
+ // Add the default language negotiation method.
+ $negotiation_info[LANGUAGE_NEGOTIATION_DEFAULT] = array(
'callbacks' => array('language' => 'language_from_default'),
'weight' => 10,
'name' => t('Default language'),
@@ -336,73 +313,60 @@ function language_negotiation_info() {
'config' => 'admin/config/regional/language',
);
- // Let other modules alter the list of language providers.
- drupal_alter('language_negotiation_info', $language_providers);
+ // Let other modules alter the list of language negotiation methods.
+ drupal_alter('language_negotiation_info', $negotiation_info);
}
- return $language_providers;
+ return $negotiation_info;
}
/**
- * Helper function used to cache the language providers results.
+ * Invokes a language negotiation method and caches the results.
*
- * @param $provider_id
- * The language provider ID.
- * @param $provider
- * The language provider to be invoked. If not passed it will be explicitly
- * loaded through language_negotiation_info().
+ * @param $method_id
+ * The language negotiation method ID.
+ * @param $method
+ * (optional) The language negotiation method to be invoked. If not passed it
+ * will be explicitly loaded through language_negotiation_info().
*
* @return
- * The language provider's return value.
+ * The language negotiation method's return value.
*/
-function language_provider_invoke($provider_id, $provider = NULL) {
+function language_negotiation_method_invoke($method_id, $method = NULL) {
$results = &drupal_static(__FUNCTION__);
- if (!isset($results[$provider_id])) {
+ if (!isset($results[$method_id])) {
global $user;
// Get the enabled languages only.
$languages = language_list(TRUE);
- if (!isset($provider)) {
- $providers = language_negotiation_info();
- $provider = $providers[$provider_id];
+ if (!isset($method)) {
+ $negotiation_info = language_negotiation_info();
+ $method = $negotiation_info[$method_id];
}
- if (isset($provider['file'])) {
- require_once DRUPAL_ROOT . '/' . $provider['file'];
+ if (isset($method['file'])) {
+ require_once DRUPAL_ROOT . '/' . $method['file'];
}
- // If the language provider has no cache preference or this is satisfied
- // we can execute the callback.
- $cache = !isset($provider['cache']) || $user->uid || $provider['cache'] == variable_get('cache', 0);
- $callback = isset($provider['callbacks']['language']) ? $provider['callbacks']['language'] : FALSE;
+ // If the language negotiation method has no cache preference or this is
+ // satisfied we can execute the callback.
+ $cache = !isset($method['cache']) || $user->uid || $method['cache'] == variable_get('cache', 0);
+ $callback = isset($method['callbacks']['negotiation']) ? $method['callbacks']['negotiation'] : FALSE;
$langcode = $cache && function_exists($callback) ? $callback($languages) : FALSE;
- $results[$provider_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
+ $results[$method_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
}
// Since objects are resources we need to return a clone to prevent the
- // provider cache to be unintentionally altered. The same providers might be
- // used with different language types based on configuration.
- return !empty($results[$provider_id]) ? clone($results[$provider_id]) : $results[$provider_id];
-}
-
-/**
- * Return the passed language provider weight or a default value.
- *
- * @param $provider
- * A language provider data structure.
- *
- * @return
- * A numeric weight.
- */
-function language_provider_weight($provider) {
- $default = is_numeric($provider) ? $provider : 0;
- return isset($provider['weight']) && is_numeric($provider['weight']) ? $provider['weight'] : $default;
+ // language negotiation method cache to be unintentionally altered. The same
+ // language negotiation methods might be used with different language types
+ // based on configuration.
+ return !empty($results[$method_id]) ? clone($results[$method_id]) : $results[$method_id];
}
/**
- * Default language provider.
+ * Returns the default language code.
*
* @return
* The default language code.
diff --git a/core/includes/locale.inc b/core/includes/locale.inc
index 8a381ed..ad7ede8 100644
--- a/core/includes/locale.inc
+++ b/core/includes/locale.inc
@@ -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']);
diff --git a/core/includes/update.inc b/core/includes/update.inc
index be9788f..1a2a242 100644
--- a/core/includes/update.inc
+++ b/core/includes/update.inc
@@ -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);
diff --git a/core/modules/locale/locale.admin.inc b/core/modules/locale/locale.admin.inc
index 2c78e17..da91631 100644
--- a/core/modules/locale/locale.admin.inc
+++ b/core/modules/locale/locale.admin.inc
@@ -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 .= '
' . $title . $description . $table . '
';
}
@@ -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.
@@ -333,7 +331,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) {
@@ -348,7 +346,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(
diff --git a/core/modules/locale/locale.api.php b/core/modules/locale/locale.api.php
index 6cf253e..90a9010 100644
--- a/core/modules/locale/locale.api.php
+++ b/core/modules/locale/locale.api.php
@@ -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';
}
}
diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install
index a75ee2e..78a74de 100644
--- a/core/modules/locale/locale.install
+++ b/core/modules/locale/locale.install
@@ -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
@@ -275,6 +275,37 @@ function locale_update_8001() {
}
/**
+ * Language providers renamed to language negotiation methods.
+ */
+function locale_update_8002() {
+ $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.
*/
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 4a786be..025e5cf 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -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'),
@@ -390,8 +390,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';
@@ -417,13 +418,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,
@@ -433,10 +434,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,
@@ -446,16 +447,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,
@@ -463,25 +464,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;
}
/**
@@ -899,7 +900,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');
@@ -936,16 +937,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;
}
}
}
diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test
index 208c5e6..256dca3 100644
--- a/core/modules/locale/locale.test
+++ b/core/modules/locale/locale.test
@@ -1301,7 +1301,7 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
variable_set('language_negotiation_' . LANGUAGE_TYPE_CONTENT, locale_language_negotiation_info());
variable_set('language_negotiation_' . LANGUAGE_TYPE_URL, locale_language_negotiation_info());
- // Change language providers settings.
+ // Change language negotiation settings.
variable_set('locale_language_negotiation_url_part', LANGUAGE_NEGOTIATION_URL_PREFIX);
variable_set('locale_language_negotiation_session_param', TRUE);
@@ -1326,16 +1326,16 @@ class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
// Check language negotiation.
require_once DRUPAL_ROOT . '/core/includes/language.inc';
$this->assertTrue(count(language_types_get_all()) == count(language_types_get_default()), t('Language types reset'));
- $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_DEFAULT;
+ $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_DEFAULT;
$this->assertTrue($language_negotiation, t('Interface language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
- $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_CONTENT) == LANGUAGE_NEGOTIATION_DEFAULT;
+ $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_CONTENT) == LANGUAGE_NEGOTIATION_DEFAULT;
$this->assertTrue($language_negotiation, t('Content language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
- $language_negotiation = language_negotiation_get(LANGUAGE_TYPE_URL) == LANGUAGE_NEGOTIATION_DEFAULT;
+ $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_URL) == LANGUAGE_NEGOTIATION_DEFAULT;
$this->assertTrue($language_negotiation, t('URL language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
- // Check language providers settings.
- $this->assertFalse(variable_get('locale_language_negotiation_url_part', FALSE), t('URL language provider indicator settings cleared.'));
- $this->assertFalse(variable_get('locale_language_negotiation_session_param', FALSE), t('Visit language provider settings cleared.'));
+ // Check language negotiation method settings.
+ $this->assertFalse(variable_get('locale_language_negotiation_url_part', FALSE), t('URL language negotiation method indicator settings cleared.'));
+ $this->assertFalse(variable_get('locale_language_negotiation_session_param', FALSE), t('Visit language negotiation method settings cleared.'));
// Check JavaScript parsed.
$javascript_parsed_count = count(variable_get('javascript_parsed', array()));
@@ -2226,7 +2226,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
'path' => 'admin/config',
'expect' => $default_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_DEFAULT,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > DEFAULT: no language prefix, UI language is default and the browser language preference setting is not used.',
),
@@ -2235,7 +2235,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT),
'path' => "$langcode/admin/config",
'expect' => $language_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_URL,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_URL,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > DEFAULT: with language prefix, UI language is switched based on path prefix',
),
@@ -2244,7 +2244,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_BROWSER),
'path' => 'admin/config',
'expect' => $language_browser_fallback_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_BROWSER,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_BROWSER,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > BROWSER: no language prefix, UI language is determined by browser language preference',
),
@@ -2253,7 +2253,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_BROWSER),
'path' => "$langcode/admin/config",
'expect' => $language_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_URL,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_URL,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (PATH) > BROWSER: with langage prefix, UI language is based on path prefix',
),
@@ -2262,7 +2262,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_BROWSER, LANGUAGE_NEGOTIATION_DEFAULT),
'path' => 'admin/config',
'expect' => $default_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_DEFAULT,
'http_header' => $http_header_blah,
'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
),
@@ -2290,7 +2290,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'locale_language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN,
'path' => 'admin/config',
'expect' => $default_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_DEFAULT,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_DEFAULT,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (DOMAIN) > DEFAULT: default domain should get default language',
),
@@ -2302,7 +2302,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
'locale_test_domain' => $language_domain,
'path' => 'admin/config',
'expect' => $language_string,
- 'expected_provider' => LANGUAGE_NEGOTIATION_URL,
+ 'expected_method_id' => LANGUAGE_NEGOTIATION_URL,
'http_header' => $http_header_browser_fallback,
'message' => 'URL (DOMAIN) > DEFAULT: domain example.cn should switch to Chinese',
),
@@ -2315,8 +2315,8 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
protected function runTest($test) {
if (!empty($test['language_negotiation'])) {
- $negotiation = array_flip($test['language_negotiation']);
- language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $negotiation);
+ $method_weights = array_flip($test['language_negotiation']);
+ language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $method_weights);
}
if (!empty($test['locale_language_negotiation_url_part'])) {
variable_set('locale_language_negotiation_url_part', $test['locale_language_negotiation_url_part']);
@@ -2326,7 +2326,7 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase {
}
$this->drupalGet($test['path'], array(), $test['http_header']);
$this->assertText($test['expect'], $test['message']);
- $this->assertText(t('Language negotiation provider: @name', array('@name' => $test['expected_provider'])));
+ $this->assertText(t('Language negotiation method: @name', array('@name' => $test['expected_method_id'])));
}
/**
@@ -2843,36 +2843,36 @@ class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase {
$language_types = variable_get('language_types', language_types_get_default());
$this->assertTrue($language_types[$type], t('Content language type is configurable.'));
- // Enable some core and custom language providers. The test language type is
- // supposed to be configurable.
+ // Enable some core and custom language negotiation methods. The test
+ // language type is supposed to be configurable.
$test_type = 'test_language_type';
- $provider = LANGUAGE_NEGOTIATION_INTERFACE;
- $test_provider = 'test_language_provider';
- $form_field = $type . '[enabled]['. $provider .']';
+ $interface_method_id = LANGUAGE_NEGOTIATION_INTERFACE;
+ $test_method_id = 'test_language_negotiation_method';
+ $form_field = $type . '[enabled]['. $interface_method_id .']';
$edit = array(
$form_field => TRUE,
- $type . '[enabled][' . $test_provider . ']' => TRUE,
- $test_type . '[enabled][' . $test_provider . ']' => TRUE,
+ $type . '[enabled][' . $test_method_id . ']' => TRUE,
+ $test_type . '[enabled][' . $test_method_id . ']' => TRUE,
);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
- // Remove the interface language provider by updating the language
+ // Remove the interface language negotiation method by updating the language
// negotiation settings with the proper flag enabled.
variable_set('locale_test_language_negotiation_info_alter', TRUE);
$this->languageNegotiationUpdate();
$negotiation = variable_get("language_negotiation_$type", array());
- $this->assertFalse(isset($negotiation[$provider]), t('Interface language provider removed from the stored settings.'));
- $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, t('Interface language provider unavailable.'));
+ $this->assertFalse(isset($negotiation[$interface_method_id]), t('Interface language negotiation method removed from the stored settings.'));
+ $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, t('Interface language negotiation method unavailable.'));
- // Check that type-specific language providers can be assigned only to the
- // corresponding language types.
+ // Check that type-specific language negotiation methods can be assigned
+ // only to the corresponding language types.
foreach (language_types_get_configurable() as $type) {
- $form_field = $type . '[enabled][test_language_provider_ts]';
+ $form_field = $type . '[enabled][test_language_negotiation_method_ts]';
if ($type == $test_type) {
- $this->assertFieldByXPath("//input[@name=\"$form_field\"]", NULL, t('Type-specific test language provider available for %type.', array('%type' => $type)));
+ $this->assertFieldByXPath("//input[@name=\"$form_field\"]", NULL, t('Type-specific test language negotiation method available for %type.', array('%type' => $type)));
}
else {
- $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, t('Type-specific test language provider unavailable for %type.', array('%type' => $type)));
+ $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, t('Type-specific test language negotiation method unavailable for %type.', array('%type' => $type)));
}
}
@@ -2898,14 +2898,14 @@ class LocaleLanguageNegotiationInfoFunctionalTest extends DrupalWebTestCase {
// previously set to configurable.
$this->checkFixedLanguageTypes();
- // Check that unavailable language providers are not present in the
- // negotiation settings.
+ // Check that unavailable language negotiation methods are not present in
+ // the negotiation settings.
$negotiation = variable_get("language_negotiation_$type", array());
- $this->assertFalse(isset($negotiation[$test_provider]), t('The disabled test language provider is not part of the content language negotiation settings.'));
+ $this->assertFalse(isset($negotiation[$test_method_id]), t('The disabled test language negotiation method is not part of the content language negotiation settings.'));
// Check that configuration page presents the correct options and settings.
$this->assertNoRaw(t('Test language detection'), t('No test language type configuration available.'));
- $this->assertNoRaw(t('This is a test language provider'), t('No test language provider available.'));
+ $this->assertNoRaw(t('This is a test language negotiation method'), t('No test language negotiation method available.'));
}
/**
diff --git a/core/modules/locale/tests/locale_test.module b/core/modules/locale/tests/locale_test.module
index a0bdf43..f6d87d6 100644
--- a/core/modules/locale/tests/locale_test.module
+++ b/core/modules/locale/tests/locale_test.module
@@ -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.
+ * Test language negotiation method.
*/
-function locale_test_language_provider($languages) {
+function locale_test_language_negotiation_method($languages) {
return 'it';
}
diff --git a/core/modules/simpletest/tests/upgrade/upgrade.language.test b/core/modules/simpletest/tests/upgrade/upgrade.language.test
index b132e10..9bcf180 100644
--- a/core/modules/simpletest/tests/upgrade/upgrade.language.test
+++ b/core/modules/simpletest/tests/upgrade/upgrade.language.test
@@ -77,5 +77,13 @@ class LanguageUpgradePathTestCase extends UpgradePathTestCase {
$this->assertFieldByName('langcode');
$this->drupalGet('node/add/page');
$this->assertNoFieldByName('langcode');
+
+ // 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');
+ // Used to be locale_language_providers_weight_language, check for both
+ // rename to 'language_interface' and 'methods'.
+ $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.'));
}
}