function field_token_info_alter in Token 7
Same name and namespace in other branches
- 8 token.tokens.inc \field_token_info_alter()
Implements hook_token_info_alter() on behalf of field.module.
We use hook_token_info_alter() rather than hook_token_info() as other modules may already have defined some field tokens.
File
- ./
token.tokens.inc, line 1359 - Token callbacks for the token module.
Code
function field_token_info_alter(&$info) {
$fields = _token_field_info();
// Attach field tokens to their respecitve entity tokens.
foreach ($fields as $field_name => $field) {
foreach (array_keys($field['bundles']) as $token_type) {
// If a token already exists for this field, then don't add it.
if (isset($info['tokens'][$token_type][$field_name])) {
continue;
}
// Ensure the tokens exist.
if (!isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) {
continue;
}
if ($token_type == 'comment' && $field_name == 'comment_body') {
// Core provides the comment field as [comment:body].
continue;
}
$info['tokens'][$token_type][$field_name] = array(
// Note that label and description have already been sanitized by _token_field_info().
'name' => $field['label'],
'description' => $field['description'],
'module' => 'token',
);
}
}
}