function token_get_list in Token 6
Same name and namespace in other branches
- 5 token.module \token_get_list()
A helper function that retrieves all currently exposed tokens, and merges them recursively. This is only necessary when building the token listing -- during actual value replacement, only tokens in a particular domain are requested and a normal array_marge() is sufficient.
Parameters
$types: A flag indicating the class of substitution tokens to use. If an object is passed in the second param, 'types' should contain the object's type. For example, 'node', 'comment', or 'user'. 'types' may also be an array of types of the form array('node','user'). If no type is specified, only 'global' site-wide substitution tokens are built.
Return value
The array of usable tokens and their descriptions, organized by token type.
3 calls to token_get_list()
- theme_token_help in ./
token.pages.inc - For a given context, builds a formatted list of tokens and descriptions of their replacement values.
- theme_token_tree in ./
token.pages.inc - Provide a 'tree' display of nested tokens.
- token_get_invalid_tokens_by_context in ./
token.module - Validate an tokens in raw text based on possible contexts.
File
- ./
token.module, line 419 - The Token API module.
Code
function token_get_list($types = 'all') {
token_include();
$return = array();
settype($types, 'array');
foreach (module_implements('token_list') as $module) {
foreach ($types as $type) {
$module_token_list = module_invoke($module, 'token_list', $type);
if (isset($module_token_list) && is_array($module_token_list)) {
foreach ($module_token_list as $category => $tokens) {
foreach ($tokens as $token => $title) {
// Automatically append a raw token warning.
if (substr($token, -4) === '-raw' && strpos($title, t('raw user input')) === FALSE && strpos($title, t('UNIX timestamp format')) === FALSE) {
$title .= ' <em>' . t('Warning: Token value contains raw user input.') . '</em>';
}
$return[$category][$token] = $title;
}
}
}
}
}
// Sort the tokens by name.
foreach (array_keys($return) as $category) {
ksort($return[$category]);
}
return $return;
}