function language_negotiation_method_invoke

Invokes a language negotiation method and caches the results.

Parameters

$method_id: The language negotiation method's identifier.

$method: (optional) An associative array of information about the method to be invoked (see hook_language_negotiation_info() for details). If not passed in, it will be loaded through language_negotiation_info().

$request: (optional) The HttpRequest object representing the current request.

Return value

A language object representing the language chosen by the method.

Related topics

1 call to language_negotiation_method_invoke()
language_types_initialize in drupal/core/includes/language.inc
Chooses a language based on language negotiation method settings.

File

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

Code

function language_negotiation_method_invoke($method_id, $method = NULL, $request = NULL) {
  $results =& drupal_static(__FUNCTION__);
  if (!isset($results[$method_id])) {
    global $user;
    $languages = language_list();
    if (!isset($method)) {
      $negotiation_info = language_negotiation_info();
      $method = $negotiation_info[$method_id];
    }
    if (isset($method['file'])) {
      require_once DRUPAL_ROOT . '/' . $method['file'];
    }

    // 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, $request) : FALSE;
    $results[$method_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
  }

  // Since objects are resources, we need to return a clone to prevent the
  // language negotiation method cache from being unintentionally altered. The
  // same methods might be used with different language types based on
  // configuration.
  return !empty($results[$method_id]) ? clone $results[$method_id] : $results[$method_id];
}