You are here

function domain_lang_negotiation_set in Domain Lang 7

Saves a list of language negotiation providers for requested domain.

Parameters

int $domain_id: The unique domain ID that is being edited.

string $type: The language negotiation type.

array $language_providers: An array of language negotiation provider weights keyed by provider ID.

2 calls to domain_lang_negotiation_set()
domain_lang_detection_selection_form_submit in ./domain_lang.admin.inc
Domain language detection and selection form submit callback.
domain_lang_types_set in ./domain_lang.module
Updates the language type configuration for requested domain.

File

./domain_lang.module, line 95
Domain Language detection and selection module.

Code

function domain_lang_negotiation_set($domain_id, $type, $language_providers) {

  // Save only the necessary fields.
  $provider_fields = array(
    'callbacks',
    'file',
    'cache',
  );
  $negotiation = array();
  $providers_weight = array();
  $defined_providers = language_negotiation_info();
  $default_types = language_types_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 whether the provider 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];
          }
        }
        $negotiation[$id] = $provider_data;
      }
    }
  }
  domain_conf_variable_set($domain_id, "language_negotiation_{$type}", $negotiation);
}