function _token_example_token_values in Examples for Developers 6
Implementation of hook_token_values().
1 call to _token_example_token_values()
- token_example_token_values in token_example/
token_example.module - Implements hook_token_values().
File
- token_example/
token_example.tokens.inc, line 31
Code
function _token_example_token_values($type, $object = NULL) {
$values = array();
if ($type == 'global') {
$values['random-sha1'] = sha1(rand());
// Create random numbers.
$values['random-num-1'] = mt_rand(0, 9);
$values['random-num-3'] = mt_rand(100, 999);
$values['random-num-10'] = mt_rand(10000, 99999) . mt_rand(10000, 99999);
// Create random letters.
$letters = range('a', 'z');
$values['random-alpha-1'] = $letters[array_rand($letters, 1)];
shuffle($letters);
$values['random-alpha-3'] = implode('', array_slice($letters, 0, 3));
shuffle($letters);
$values['random-alpha-10'] = implode('', array_slice($letters, 0, 10));
// Create a UNIX timestamp token.
$time = time();
$tz = variable_get('date_default_timezone', 0);
$values['site-date-timestamp'] = format_date($time, 'custom', 'Y', $tz);
}
elseif ($type == 'node' && !empty($object)) {
$format = $object->format || variable_get('filter_default_format', 1);
$format = filter_format_load($object->format);
if (!empty($format->name)) {
$values['node-format'] = check_plain($format->name);
}
if (isset($object->revision_timestamp)) {
$values += token_get_date_token_values($object->revision_timestamp, 'node-revision-');
}
// Node tokens go here.
}
return $values;
}