Version 1.9 (checked in on 2010/03/12 at 14:33:02 by dries)
Drupal placeholder/token replacement system.
Provides a set of extensible API functions for replacing placeholders in text with meaningful values.
For example: When configuring automated emails, an administrator enters standard text for the email. Variables like the title of a node and the date the email was sent can be entered as placeholders like [node:title] and [date:short]. When a Drupal module prepares to send the email, it can call the token_replace() function, passing in the text. The token system will scan the text for placeholder tokens, give other modules an opportunity to replace them with meaningful text, then return the final product to the original module.
Tokens follow the form: [$type:$name], where $type is a general class of tokens like 'node', 'user', or 'comment' and $name is the name of a given placeholder. For example, [node:title].
In addition to raw text containing placeholders, modules may pass in an array of objects to be used when performing the replacement. The objects should be keyed by the token type they correspond to. For example:
<?php // Load a node and a user, then replace tokens in the text. $text = 'On [date:short], [user:name] read [node:title].'; $node = node_load(1); $user = user_load(1); // [date:...] tokens use the current date automatically. $data = array('node' => $node, 'user' => $user); return token_replace($text, $data); ?>
Some tokens may be chained in the form of [$type:$pointer:$name], where $type is a normal token type, $pointer is a reference to another token type, and $name is the name of a given placeholder. For example, [node:author:mail]. In that example, 'author' is a pointer to the 'user' account that created the node, and 'mail' is a placeholder available for any 'user'.
|token_find_with_prefix||Given a list of tokens, return those that begin with a specific prefix.|
|token_generate||Generate replacement values for a list of tokens.|
|token_info||Returns metadata describing supported tokens.|
|token_replace||Replace all tokens in a given string with appropriate values.|
|token_scan||Build a list of all token-like patterns that appear in the text.|