function userpoints_token_info in User Points 7
Same name and namespace in other branches
- 7.2 userpoints.module \userpoints_token_info()
Implements hook_token_info().
File
- ./
userpoints.module, line 632
Code
function userpoints_token_info() {
$types = array(
'userpoints_transaction' => array(
'name' => t('!Points transaction', userpoints_translation()),
'description' => t('A single transaction that grants or removes a certain amount of points from a user.'),
'needs-data' => 'userpoints_transaction',
),
'userpoints' => array(
'name' => t('!Points', userpoints_translation()),
'description' => t('Amount of !points a user has.', userpoints_translation()),
'needs-data' => 'user',
),
'maxuserpoints' => array(
'name' => t('Maximal !points', userpoints_translation()),
'description' => t('Maximal amount of !points a user had at any time.', userpoints_translation()),
'needs-data' => 'user',
),
);
$tokens = array();
$tokens['user']['points'] = array(
'name' => t('!Points', userpoints_translation()),
'description' => t('The amount of !points this user has. If there are multiple categories, only the default category is taken into account.', userpoints_translation()),
'type' => 'userpoints',
);
$tokens['user']['maxpoints'] = array(
'name' => t('Maximal !points', userpoints_translation()),
'description' => t('The highest amount of !points a user had at any given point. If there are multiple categories, only the default category is taken into account.', userpoints_translation()),
'type' => 'userpoints',
);
$categories = userpoints_get_categories();
if (count($categories) > 1) {
foreach ($categories as $tid => $category) {
$tokens['userpoints']['category-' . $tid] = array(
'name' => t('!Points in category %category', array_merge(array(
'%category' => $category,
), userpoints_translation())),
'description' => t('The amount of !points this user has in that category.', userpoints_translation()),
);
$tokens['maxuserpoints']['category-' . $tid] = array(
'name' => t('Maximal !points in category %category', array_merge(array(
'%category' => $category,
), userpoints_translation())),
'description' => t('The highest amount of !points a user had at any given point in that category.', userpoints_translation()),
);
}
}
$tokens['userpoints']['all'] = array(
'name' => t('Total !points', userpoints_translation()),
'description' => t('Total amount of !points over all categories.', userpoints_translation()),
);
$tokens['maxuserpoints']['all'] = array(
'name' => t('Total maximum !points', userpoints_translation()),
'description' => t('Total amount of maximal !points over all categories.', userpoints_translation()),
);
// Re-use property definition that is used for rules integration.
foreach (_userpoints_userpoints_transaction_properties() as $property => $info) {
$tokens['userpoints_transaction'][$property] = array(
'name' => $info['label'],
'description' => $info['description'],
);
if (in_array($info['type'], array(
'date',
'user',
))) {
$tokens['userpoints_transaction'][$property]['type'] = $info['type'];
}
if ($property == 'tid') {
// tid is of type taxonomy_term.
$tokens['userpoints_transaction'][$property]['type'] = 'term';
}
}
// Add an additional token for the absolute points.
$tokens['userpoints_transaction']['points-abs'] = array(
'name' => t('!Points absolute', userpoints_translation()),
'description' => t('The absolute (positive) amount of !points of this transaction.', userpoints_translation()),
);
return array(
'types' => $types,
'tokens' => $tokens,
);
}