This site is not supported for Internet Explorer 6. It might look funny or even not function properly if you are using this browser.
You upgrade Flash as soon as they get a new version. Why not get an updated browser?
Try Firefox, Chrome or if you love and breath Microsoft than IE7.

Providing custom tokens to token module in Drupal 6

Many Drupal modules integrate with the Token module and it is used in almost every Drupal install for defining path aliases and even custom breadcrumbs.  Its so popular that in the upcoming Drupal 7 release token is integrated into core.  

If you're developing your own custom module why not integrate with token and allow your users more flexibility with what they can do with your content? With two simple functions you can easily integrate your module with Token.

function mymodulename_token_values($type, $object = NULL) {
	if ($type == 'node') {
		if ($object->type=="NODETYPE") {
			$values["token-name1"] = check_plain($object->var1;
			$values["token-name2"] = check_plain($object->var2);
		}		
    return $values;
  }
}

In the above function $type can also be $user or $global. After declaring what the values are for your token you need to define descriptive text for them:

function mymodulename_token_list($type = 'all') {
  if ($type == 'node' || $type =='all') {
    $tokens['cat']['token-name1']            = t('A description of token name 1');
    $tokens['cat']['token-name2']          = t('Token name 2's description');
    return $tokens;
  }
}

That's all their is to it. The documentation page on drupal.org gives good examples of this as well as points you to token_node.inc inside the Token module for more information.

Filed under:

No comments

Add your comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <br /> <br> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated.

Google Reader Shared Items

User login