开发者

how to implement placeholder tokens in drupal

开发者 https://www.devze.com 2023-02-07 16:22 出处:网络
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 yettaken from drupal.org

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;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号