function language_negotiation_set

Saves a list of language negotiation methods for a language type.

Parameters

$type: The language type.

$method_weights: An array of language negotiation method weights keyed by method ID.

Related topics

7 calls to language_negotiation_set()
LanguageUILanguageNegotiationTest::runTest in drupal/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php
language_install in drupal/core/modules/language/language.install
Implements hook_install().
language_negotiation_configure_form_submit in drupal/core/modules/language/language.admin.inc
Submit handler for language negotiation settings.
language_negotiation_purge in drupal/core/includes/language.inc
Removes any language negotiation methods that are no longer defined.
language_types_set in drupal/core/includes/language.inc
Updates the language type configuration.

... See full list

File

drupal/core/includes/language.inc, line 362
Language Negotiation API.

Code

function language_negotiation_set($type, $method_weights) {

  // Save only the necessary fields.
  $method_fields = array(
    'callbacks',
    'file',
    'cache',
  );
  $negotiation = array();
  $negotiation_info = language_negotiation_info();
  $default_types = language_types_get_configurable(FALSE);

  // 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 whether the method is defined and has the right type.
      if (isset($types[$type])) {
        $method_data = array();
        foreach ($method_fields as $field) {
          if (isset($method[$field])) {
            $method_data[$field] = $method[$field];
          }
        }
        $negotiation[$method_id] = $method_data;
      }
    }
  }
  variable_set("language_negotiation_{$type}", $negotiation);
}