function token_token_values in Token 5
Same name and namespace in other branches
- 6 token.module \token_token_values()
Sample implementation of hook_token_values().
Parameters
type: A flag indicating the class of substitution tokens to use. If an object is passed in the second param, 'type' should contain the object's type. For example, 'node', 'comment', or 'user'. If your implementation of the hook inserts globally applicable tokens that do not depend on a particular object, it should only return values when $type is 'global'.
object: Optionally, the object to use for building substitution values. A node, comment, user, etc.
Return value
A keyed array containing the substitution tokens and the substitution values for the passed-in type and object.
File
- ./
token.module, line 86 - The Token API module.
Code
function token_token_values($type, $object = NULL) {
global $user;
$values = array();
switch ($type) {
case 'global':
// Current user tokens.
$values['user-name'] = $user->uid ? $user->name : variable_get('anonymous', t('Anonymous'));
$values['user-id'] = $user->uid ? $user->uid : 0;
$values['user-mail'] = $user->uid ? $user->mail : '';
// Site information tokens.
$values['site-url'] = url('<front>', NULL, NULL, TRUE);
$values['site-name'] = check_plain(variable_get('site_name', t('Drupal')));
$values['site-slogan'] = check_plain(variable_get('site_slogan', ''));
$values['site-mission'] = filter_xss_admin(variable_get('site_mission', ''));
$values['site-mail'] = variable_get('site_mail', '');
$values += token_get_date_token_values(NULL, 'site-date-');
$values['site-date'] = $values['site-date-small'];
// Current page tokens.
$values['current-page-title'] = drupal_get_title();
$alias = drupal_get_path_alias($_GET['q']);
$values['current-page-path'] = $alias;
$values['current-page-path-raw'] = check_plain($alias);
$values['current-page-url'] = url($_GET['q'], NULL, NULL, TRUE);
$page = isset($_GET['page']) ? $_GET['page'] : '';
$pager_page_array = explode(',', $page);
$page = $pager_page_array[0];
$values['current-page-number'] = (int) $page + 1;
$values['page-number'] = $values['current-page-number'];
break;
}
return $values;
}