GVS is now part of Acquia. Acquia logo

Introducing Token Starterkit - Simple Introduction to Creating your own Drupal Tokens

Greg's picture

There seems to be a new pattern emerging in Drupal and I want to let you know that the Token module has joined the bandwagon with a "Token Starter Kit"

History of the Starter Kit in Drupal: Zen Theming

When the Zen project started it's goal was to be a really solid base HTML theme with tons of comments in the templates so that a new themer could take it, modify it, and end up with a great theme. Unfortunately, that second step of modifying it meant that people ran into all sorts of support issues that were hard to debug and they were in trouble when a new version of Zen came out - they weren't really running Zen any more.

How to use the Token Starter Kit

The Token Starter Kit is meant to be similarly easy for folks to use. The idea is that if you just open up the token module itself and start adding tokens then you are "hacking a contrib" (modifying it) and you will have to remember to make those changes again when you upgrade. Bad news. It's also not particularly simple to understand how the module works (it's got includes, and hooks, oh my!).

Enter the tokenSTARTER module. Just copy the tokenSTARTER .info and .module files to a new directory in your modules directory, rename them, and rename all the functions inside to match the filenames. This gives you a clean place to start adding in your own tokens. So, go for it. You'll see that it's quite simple and all you need are two hooks.

Documentation on Token API

There's also an API.txt file and README.txt file which explain how to write tokens in general. Lots of great advice in there.

Comments

Adding a token for filename (minus the .jpg or .whatever)

Hello I have download and installed the tokenSTARTER kit renamed the files and changed the contents as per the instructions "change every instance of STARTER" Therfore i have tokenCUSTOM.info and tokenCUSTOM.module in the token directory and have enabled the tokenSTARTER and tokenCUSTOM modules.

Background: Using Ubercart, I would like to be able to use a default token value of the uploaded images filename to the AltTitle field at this page.

http://mysite.com/admin/content/node-type/product/fields/field_image_cache

How do i go about adding a token for a filename? is this possible or am i doomed to enter them in manually.

PS i have posted here to Ubercart for help as well.

http://www.ubercart.org/comment/reply/16920/53412

Thanks to anyone in advance for helping me out!

token_replace

I have used tokens of the form //Email confirmatory message.

Group: [message:group-name]

Author: [message_author:user]

Message: [message:message-body] //html tags are sent in the message body

I need to remove these html tags using strip_tags or hook_token_replace. Can you give me a working example of how i can do this?

GVS projects

CertifiedToRock.com was created to allow community members and employers to get a sense of someone's involvement with the Drupal project.

GVS is now part of Acquia.

Acquia logo

Contact Acquia if you are interested in a Drupal Support or help with any products GVS offered such as the Conference Organizing Distribution (COD).

We Wrote the Book On Drupal Security:

Cracking Drupal Book Cover