The documentation could use some extending.
Taking hook_token_info as a victim here:
For example, what's 'needs-data', and what can be used as the key in the 'types' and 'tokens' arrays.
jhodgdon: needs-data tells token what type of data the token needs to have available, sucn as a node, a user, a comment, etc. in order to figure out what the token value is.
jhodgdon: http://api.drupal.org/api/function/hook_tokens/7 sort of implies you can make up your own names
jhodgdon: basically it would be the key in http://api.drupal.org/api/function/token_replace/7 in $data, that the caller of token_replace provides.
So, although it looks like it, the 'needs-data' and other keys are made up (they don't need to match a DB table, entity name, etc. However, in most cases they should, as noted in the core token implementations)
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 881908-6.patch | 5.61 KB | jhodgdon |
| #3 | 881908.patch | 5.62 KB | jhodgdon |
Comments
Comment #1
bojanz commentedTo elaborate, you specify the keys that you want because you're the one who runs token_replace() providing the needed data later on.
So if I do this:
Later on when I need the tokens replaced (for example, for sending an email), I do
I hope this helps
Comment #2
jhodgdonThanks for reporting this and for explaining how it actually works. We need to get this information into the documentation...
Comment #3
jhodgdonHere's a patch, with proposed (hopefully better) documentation for the token hooks.
Comment #4
jhodgdon#3: 881908.patch queued for re-testing.
Comment #6
jhodgdonHere's a reroll of this patch.
Comment #7
bojanz commentedVery nice.
Comment #8
dries commentedGreat improvements. Committed to CVS HEAD.
Comment #9
dave reidGah, missed reviewing this since it wasn't in the token system queue or tagged with 'token'. Lovely improvements to the docs!