1 token.inc | token_get_info($token_type = NULL, $token_name = NULL) |
Retrieve, sort, store token info from the cache.
Parameters
string|NULL $token_type: The optional token type that if specified will return $info['types'][$token_type].
string|NULL $token_name: The optional token name if specified will return $info['tokens'][$token_type][$token_name].
Return value
array: An array of all token information from hook_token_info(), or the array of a token type or specific token.
See also
File
- core/
includes/ token.inc, line 282 - Backdrop placeholder/token replacement system.
Code
function token_get_info($token_type = NULL, $token_name = NULL) {
global $language_content;
$cache_token = cache('token');
// Use the advanced backdrop_static() pattern, since this is called very often.
static $backdrop_static_fast;
if (!isset($backdrop_static_fast)) {
$backdrop_static_fast['token_info'] = &backdrop_static(__FUNCTION__);
}
$token_info = &$backdrop_static_fast['token_info'];
if (empty($token_info)) {
$cid = "info:{$language_content->langcode}";
if ($cache = $cache_token->get($cid)) {
$token_info = $cache->data;
}
else {
$token_info = token_info();
foreach (array_keys($token_info['types']) as $type_key) {
if (isset($token_info['types'][$type_key]['type'])) {
$base_type = $token_info['types'][$type_key]['type'];
// If this token type extends another token type, then merge in
// the base token type's tokens.
if (isset($token_info['tokens'][$base_type])) {
$token_info['tokens'] += array($type_key => array());
$token_info['tokens'][$type_key] += $token_info['tokens'][$base_type];
}
}
else {
// Add a 'type' value to each token type so we can properly use
// token_type_load().
$token_info['types'][$type_key]['type'] = $type_key;
}
}
// Pre-sort tokens.
backdrop_sort($token_info['types'], array('name' => SORT_STRING));
// Store info in cache for future use.
$cache_token->set($cid, $token_info);
}
}
if (isset($token_type) && isset($token_name)) {
return isset($token_info['tokens'][$token_type][$token_name]) ? $token_info['tokens'][$token_type][$token_name] : NULL;
}
elseif (isset($token_type)) {
return isset($token_info['types'][$token_type]) ? $token_info['types'][$token_type] : NULL;
}
else {
return $token_info;
}
}