You are here

function token_get_list in Token 5

Same name and namespace in other branches
  1. 6 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.

2 calls to token_get_list()
theme_token_help in ./token.module
For a given context, builds a formatted list of tokens and descriptions of their replacement values.
token_get_invalid_tokens_by_context in ./token.module
Validate an tokens in raw text based on possible contexts.

File

./token.module, line 371
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) {
    $function = $module . '_token_list';
    foreach ($types as $type) {
      $result = $function($type);
      if (is_array($result)) {
        foreach ($result 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, '1269441371') === FALSE) {
              $title .= ' <em>' . t('Warning: Token value contains raw user input.') . '</em>';
            }
            $return[$category][$token] = $title;
          }
        }
      }
    }
  }
  return $return;
}