18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Building an Admin Interface<br />

Debugging mail problems<br />

There are a variety of reasons why an e-mail might not be delivered.<br />

If the the recipient's address does not exist or there is another problem<br />

on the receiving end, the mail will be bounced back to the e-mail<br />

address specified in the sixth argument of drupal_mail() (the site<br />

administrator in this example.). In the case of a misconfigured local<br />

system, you may be able to find more information in PHP's error logs. The<br />

Reroute Mail module can be helpful if you are having problems sending<br />

mail on your development server:<br />

http://drupal.org/project/reroute_e-mail<br />

This is all good, and we actually have a fully functional module now. However, there<br />

is one more issue we should look at addressing.<br />

The token system<br />

It would be nice if we could include some personalized information in the mail text<br />

without having to hardcode it in the module configuration form. For instance, we<br />

should be able to include the login of the user being warned, or the name of the site<br />

admin. This leads us into our final topic, using <strong>Drupal</strong>'s token system.<br />

What are tokens?<br />

A token is a small piece of text that can be placed into a piece of text via the use of a<br />

placeholder. When the text is passed through the function token_replace(), then<br />

the tokens are replaced with the appropriate information. Tokens allow users to<br />

include data that could change in text blocks, without having to go back and change<br />

it everywhere they're referenced.<br />

In previous versions of <strong>Drupal</strong>, tokens were implemented using the<br />

contributed module named, not surprisingly, Token. This functionality<br />

proved to be so popular and widely used that it was included in core<br />

for <strong>Drupal</strong> 7.<br />

A sample token is [site:name]. When text containing this token is passed through<br />

token_replace(), it is replaced with your site's name as defined in Home |<br />

Administer | Configuration | Site information. If you change your site's name,<br />

then in the future all text containing this token will reflect this change. <strong>Drupal</strong><br />

exposes a variety of tokens containing information on users, nodes, site-wide<br />

configuration, and more.<br />

[ 146 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!