Could we add a third parameter to hook_token_value when called with a field?
Here is the code that's responsible for this now (includes/content.token.inc):
function content_token_values($type, $object = NULL) {
$tokens = array();
if ($type == 'node') {
$node = $object;
// Prevent against invalid 'nodes' built by broken 3rd party code.
if (isset($node->type)) {
$type = content_types($node->type);
$node->build_mode = 'token';
$node->content = array();
content_view($node);
// The formatted values will only be known after the content has been rendered.
drupal_render($node->content);
content_alter($node);
$field_types = _content_field_types();
foreach ($type['fields'] as $field) {
$items = $node->{$field['field_name']};
$function = $field_types[$field['type']]['module'] . '_token_values';
if (!empty($items) && function_exists($function)) {
$token_values = $function('field', $items);
foreach ($token_values as $token => $value) {
$tokens[$field['field_name'] .'-'. $token] = $value;
}
}
}
}
}
return $tokens;
}
The neccessary modification would be just:
- token_values = $function('field', $items);
+ token_values = $function('field', $items, $node);
This way when extracting the value for a field's token we would have access to the node. I want to add some translation support to content_taxonomy through a "content_taxonomy-term-translated" token. I have found no other ideas how to get hold of the node's language in hook_token_values.