1 system.pages.inc | system_token_browser_build_level($type, array $ancestors, $show_restricted) |
Build a level of the token hierarchy.
@since 1.30.0 Function added.
Parameters
string $type: The type to build a level for.
array $ancestors: The ancestors of the given type. This allows the complete token to be constructed.
bool $show_restricted: A flag to indicate if restricted tokens should be shown.
Return value
array: The constructed level of tokens as an array keyed by token.
File
- core/
modules/ system/ system.pages.inc, line 223 - System module non-administrative page callbacks.
Code
function system_token_browser_build_level($type, array $ancestors, $show_restricted) {
global $language;
$level = array();
$info = token_get_info();
if (!isset($info['types'][$type]) || !isset($info['tokens'][$type])) {
return $level;
}
if ($entity_token = entity_get_info($type)) {
$type = $entity_token['token type'];
}
$cid = 'token-browser-level:' . hash('sha256', serialize(array(
'type' => $type,
'ancestors' => $ancestors,
'language' => $language->langcode,
'show_restricted' => $show_restricted,
)));
if ($cache = cache_get($cid, 'cache_token')) {
return $cache->data;
}
foreach ($info['tokens'][$type] as $child => $child_info) {
$raw_token_parts = $ancestors;
if (in_array($child, array_slice($raw_token_parts, 1), TRUE)) {
continue;
}
if (!$show_restricted && !empty($child_info['restricted'])) {
continue;
}
$raw_token_parts[] = $child;
if (!empty($child_info['dynamic'])) {
$raw_token_parts[] = '?';
}
$raw_token = '[' . implode(':', $raw_token_parts) . ']';
$level[$child]['name'] = $child_info['name'];
$level[$child]['description'] = $child_info['description'];
$level[$child]['token'] = $child;
if (isset($child_info['type']) && isset($info['types'][$child_info['type']])) {
$level[$child]['type'] = $child_info['type'];
}
$level[$child]['raw'] = $raw_token;
$level[$child]['ancestors'] = $ancestors;
}
cache_set($cid, $level, 'cache_token');
return $level;
}