• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

Drupal hook: hook_mail_alter

When sending e-mails or newsletters from your website, you might want to inject some information like website name, disclaimer, copy right information, unsubscribe link and such. Just like hook_form_alter, you can use hook_mail_alter to virtually alter anything in the mail just before Drupal sends the e-mail. You can even change the mime type of the email, for example, from plain text to HTML and vice versa.
Here is the syntax/signature of the hook

  • Drupal 5: hook_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers)
  • Drupal 6, 7: hook_mail_alter(&$message)

$message has the following key-value pairs:

  • 'id': Unique id of the mail being sent.
  • 'to': The destination e-mail address(es)

Image menu

in Project codes

This CodeLet will allow you to add an image to a menu by overriding the menu in the template.php file of you theme. Also, the module offer admin side control to select and put the image to a menu item.

Node Visitors

in Project codes

This CodeLet adds a local task on node page which lists all the unique visitors of the node. You can configure the profile fields to be shown list.

Node information

in Project codes

This CodeLet shows a link on nodes to request more information for a node. By clicking the link, the user will be redirected to the site wide contact page and the subject field of the contact form is filled with the node title. Also, the link to the node will be added just before the mail will be sent. Thus preventing the user from modifying the link.

Grid of terms in a block

in Project codes

This CodeLet show how to display terms in a vocabulary as block. The CodeLet will display the terms, along with term icon, if taxonomy image module is installed, in a grid of 4X4. The block is configurable. You can select which vocabulary to show the terms from. Its quite attractive and can be used on front page.

Project codes

This CodeBook contains CodeLets from different projects that are allowed to publish to community. All the CodeLets under this CodeBook are published under GNU/GPL license. You can use, share, modify and publish it under GNU/GPL license.

CodeLets

  • Grid of terms in a block
    • This CodeLet show how to display terms in a vocabulary as block. The CodeLet will display the terms, along with term icon, if taxonomy image module is installed, in a grid of 4X4. The block is configurable. You can select which vocabulary to show the terms from. Its quite attractive and can be used on front page.
  • Node information
    • This CodeLet shows a link on nodes to request more information for a node. By clicking the link, the user will be redirected to the site wide contact page and the subject field of the contact form is filled with the node title. Also, the link to the node will be added just before the mail will be sent. Thus preventing the user from modifying the link.
  • Node Visitors
    • This CodeLet adds a local task on node page which lists all the unique visitors of the node. You can configure the profile fields to be shown list.
  • Image menu
    • This CodeLet will allow you to add an image to a menu by overriding the menu in the template.php file of you theme. Also, the module offer admin side control to select and put the image to a menu item.

Drupal hook: hook_view

The full view of a node including all the information associated with the nodes like author, node posted date, file attached to the node and any other data that are associated by other custom modules is managed by hook_view. The main goal and use of the hook_view is to allow the node modules to add extra information and manage those extra information to display when viewing the node. Nodes can have tease view as well as page view. On teaser view, only some of the information associated with the node is displayed; we can say its an overview of the node. On page view, all the information associated with the node is displayed.

<?php
/**
* Implementation of hook_view
* @param $node
* @param $teaser
* @param $page
* @return unknown_type
* @author Drupal Developer
*/

Drupal hook: hook_block

Blocks are the one of the basic and most fascinating features of Drupal. With block you can display information in the form of block by saving and utilizing the screen area. Here is an example of implementation of hook_block

<?php
/**
* Implementation of hook_block
*
* @param $op
* @param $delta
* @param $edit
* @return $block
* @author Drupal Developer
*/
function browse_info_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[1] = array(
'info' => t("Browse information by category"),
'status' => 1,
'region' => 'content',
'weight' => 0,
);

return $blocks;
case 'configure':
$am__vocabulary = _get_vocabulary();
$am__imagecache = _get_imagecache();

Drupal hook: hook_cron

You've just published a Drupal website and people find it very useful. So, they started signing up with your website and its really very good traffic now. You have planned to implement some features and you want to let know about to all the members of the site. There are two ways: you send e-mails to individuals by using their contact form or implement a system with which you create a node and the site itself sends e-mails. How about sending the e-mails at specific period of time? ohh.. yeah. that's great. Drupal's hook_run makes it happen. Since, there are more features to come, you want to do this every time you have something new to let others know about, you would use hook_cron, which performs specific tasks assigned to it periodically.

Share your Drupal codes

We are pleased to announce a successful implementation of CodeBook, a feature which lets you share your Drupal codes and shows your Drupal skill to the world. By creating CodeBooks, you can showcase your Drupal Development skills by referring the CodeBooks to your potential clients as well as recruiters. This is all about helping the community in learning the Drupal in an easier way. So, Join the movement!

Syndicate content

Recent comments

toolbar powered by www.mit3xxx.de