Somewhere between beta2 and beta5 token_tokens added handling for the generic 'entity' token collection. This means hook_tokens is called twice for each entity field, once with the type of the entity (e.g. 'node', 'user' or 'profile2') and once with the type of 'entity'. Modules that only look at the field name to decide whether to generate a token will now produce the token twice. module_invoke_all in token_generate then aggregates the results which generates an array in $replacements for that token name. If the token is used token_replace will generate an error 'Array to string conversion in token_replace() line 97' and the token is replaced with 'Array'.
I have noticed this behaviour with fields generated using the computed_field module but I suspect others are affected as well.
The workaround I use is to use the field token 'field_xyz' rather than 'field-xyz' and set up the tokens view mode if the entity's 'manage display' page.
Comments
Comment #1
dave reidIF modules are not checking the $type parameter in hook_tokens() then they are doing it wrong.
Comment #2
dave reidMoving this issue to the Computed field issue queue.
I see the following problems in computed_field.module:
1. The module is adding tokens for fields that may be on other entity types and not on nodes.
2. Unchecked $type parameter in computed_field_tokens().
Comment #3
atlea commentedI am getting notices that probably are related to these problems.
Atle
Comment #4
colanAdding tag.
Comment #5
colanAs it was causing all kinds of problems, I removed the broken Token implementation entirely. Use field tokens instead. If you want raw values, or other different things displayed, play with your display code. Committed to ae74983.
If someone has a good use case for a specific token implementation for Computed Field, please open a feature request, and provide a patch that doesn't take down everyone else's tokens. ;)