1 language.inc | language_provider_invoke($provider_id, $provider = NULL) |
Helper function used to cache the language negotiation providers results.
Parameters
$provider_id: The language negotiation provider's identifier.
$provider: (optional) An associative array of information about the provider to be invoked (see hook_language_negotiation_info() for details). If not passed in, it will be loaded through language_negotiation_info().
Return value
A language object representing the language chosen by the provider.:
Related topics
File
- core/
includes/ language.inc, line 417 - Language Negotiation API.
Code
function language_provider_invoke($provider_id, $provider = NULL) {
$results = &backdrop_static(__FUNCTION__);
if (!isset($results[$provider_id])) {
global $user;
// Get the enabled languages only.
$languages = language_list(TRUE);
if (!isset($provider)) {
$providers = language_negotiation_info();
if (isset($providers[$provider_id])) {
$provider = $providers[$provider_id];
}
}
if (isset($provider['file'])) {
require_once BACKDROP_ROOT . '/' . $provider['file'];
}
// If the language negotiation provider has no cache preference or this is
// satisfied we can execute the callback.
$cache = !isset($provider['cache']) || $user->uid || $provider['cache'] == config_get('system.core', 'cache');
$callback = isset($provider['callbacks']['language']) ? $provider['callbacks']['language'] : '';
$langcode = $cache && function_exists($callback) ? $callback($languages) : FALSE;
$results[$provider_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
}
// Since objects are resources, we need to return a clone to prevent the
// language negotiation provider cache from being 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];
}