General Question

skorned's avatar

Drupal tokens tutorial/help?

Asked by skorned (97 points ) July 12th, 2009

If you’re too lazy to read through this question, could you just direct me to some site where they have posted a tutorial on using the ‘token’ module’s string replacement functions when creating a module. Or atleast some sample code, with sample calls to the token_replace function?

I’m creating a form alter module in drupal, which will alter the node addition form to set some default values in the form’s fields. Now I have got the code to set the default value working as such:
$form[‘locations’][0][’#location_settings’][‘form’][‘fields’][‘name’][‘default’] = ‘Neil’;

Now in place of the string ‘Neil’, I want to get the text replacements of tokens, specifically, I wanna retrieve the uid of the author of the node, then look up a detail of his (his location). What would the token replacement string be? something like… token_replace($form[‘uid’][‘locations’][0][’#default_value’][‘city’]);

right? and I’m not sure what kinda value I have to pass for the $object param.

Anyhow, this is giving me some parse errors, and frankly, I’m astonished by the complete lack of documentation on how to use tokens, and the syntax.

Observing members: 0 Composing members: 0

3 Answers

Saturated_Brain's avatar

Ack! Computer script! My eyes! Get it away from me!

Hasn’t google been able to help you out?

skorned's avatar

nope…tried google a LOT…..
anyhow, i figured it out using extensive debugging methods and trying out various combinations and permutations of token and variable syntax…thanks anyhow

Saturated_Brain's avatar

No problem. Just didn’t like the look of an abandoned question, that’s all. =)

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther