how to implement placeholder tokens in drupal
How can one insert a token into a textarea?
There is a token inse开发者_运维知识库rt module, but that does not have a stable version out yet
taken from drupal.org
hook_token_values($type, $object = NULL, $options = array())
This function should return a keyed array of placeholders, and their replacement values. $type contains the current context -- 'node', 'user', 'global', etc. $object contains the specific node, user, etc. that should be used as the basis for the replacements. Only generate and return replacement tokens when $type is something that your module can really deal with. That helps keep things speedy and avoid needlessly searching for jillions of replacement tokens. The $options array can contain additional options (exact use is dynamic and not easily documented).
For example:
function my_user_token_values($type, $object = NULL, $options = array()) {
if ($type == 'user') {
$user = $object;
$tokens['name'] = $user->name;
$tokens['mail'] = $user->mail;
return $tokens;
}
}
精彩评论