If your hosting is providing you shell access, Drush (Drupal Shell) is a blessing if you want to make some repetitive actions faster, easier and more robust. The installation bit might be a little scary for new users (especially if it is the first time you hear the terms shell, bash, etc.) but it is definitely worth the effort.

With drush, among many many other things (e.g. install, update, enable/disable contributed modules), you can also:

backup (mysql dump) your database

    $ drush sql dump --result-file=backup.sql

reload/copy (mysql load) your database (some_database)

    $ drush sql connect #connect to MySQL via Drush
    $ mysql some_database < backup.sql #load file into database

Source: Nathan Rambeck

Author: (16)


Redirect to the referring page after login in Drupal

Redirection might become a little problematic if you are not sure how to do it in Drupal. You can add at the end of your link ?destination=redirect/here but either the link might not work properly for some reason or you might prefer the referrer page to be dynamic.

Here is the solution:

$destination = drupal_get_destination();
print l('Login', 'user/login', array('query' => $destination));

Source: cglusky

Author: (16)


In Drupal, when you create a select field and you make that field required, you are very likely to run into a weird issue.

The required field will get the first value of the list, making it very easy for the user to overlook it. If the user overlooks it, there is a high probability the first value will not be the correct one. Putting an empty first value does not work as well, as Drupal will just ignore it.

This is actually an easy problem to tackle but the answer might be a little difficult to find. First you should now that you can differentiate the label and the value while configuring the select list. The convention is value|label.

To solve our problem, we are just going to use null value for the first value of the select list. For example |-- Please select --

So a required language list will be something like this. The first value being empty will make Drupal ask for something else if left untouched:

|-- Please select --

PS: You do not have to use labels for other values

Source: grendzy

Author: (16)


“Login or register to vote” snippet for Fivestar module in Drupal

VotingAPI and Fivestar function very well if you want to implement a voting widget and all necessary functionalities that comes with it.

When I wanted to implement “Login to Vote” functionality -voting widget behaving similar to the comments for anonymous users-, I came across the following snippet which works flawlessly. Just rename [nameofyourtheme] to your theme name (without []) and insert it in your template.php file and you are good to go.

* Display a static fivestar value as stars with a title and description.

function [nameofyourtheme]_fivestar_static_element($value, $title = NULL, $description = NULL) {
  $output .= '<div class="fivestar-static-form-item">';
  $element = array(
    '#type' => 'item',
    '#title' => $title,

  $output .= theme('form_element', $element, $value);
  $output .= '<div class="description">'. t('Login or register to vote.') .'</div>';
  $output .= '</div>';
  return $output;

Source: quicksketch

Author: (16)


It might be very convenient to create a page with PHP-filter and then insert a drupal_goto function to divert the user according to the conditions (e.g. logged-in, role ).

However, you should be careful not to break Cron with drupal_goto. As cron will get stuck trying to index your page with drupal_goto function.

In order to prevent this you can check for the $_SERVER['SCRIPT_NAME']. For example:

if ($_SERVER['SCRIPT_NAME'] != '/cron.php') {

Author: (16)


Two useful snippets for block visibility in Drupal

Here are two very useful snippets that you should keep somewhere easy to access and safe:

To display the block ONLY on Node View but not on Node Edit:

// Only show on true node VIEW pages. Not node/add or node/n/edit etc
return (arg(0)=='node' && is_numeric(arg(1)) && (!arg(2)));

The same principle works with ‘user’ as well if you want the block to show only in user profile but not in registration, request password screens.

Source: Drupal PHP snippets

To display the block ONLY on logged-in user's account page but not on other user's account page:

global $user;
// Return TRUE if we have a user viewing her/his own user profile.
return $user->uid && arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid;

by Nedjo

Author: (16)


Creating profile picture block in Drupal

Even though, it is quite easy to figure it out with a little PHP and Drupal knowledge, it might still be frustrating for beginners to find an easy answer for this question.

Try creating a block with the following PHP code (do not forget to select the PHP code as input format):

$owner = user_load(arg(1));
print theme('user_picture', $owner);

Most probably, you will want to limit the visibility of the block to user/* and/or users/* (if you are using pathauto module).

Source: dalad’s comment

Author: (16)


Rules module provides a very powerful infrastructure to define conditionally executed actions based on occurring events. Let’s say a major upgrade to the core Triggers module. It makes a lot of sense to use Rules with Token module to create robust triggers, actions and even workflows without writing a single line of code.

For a recent project, I needed to access the vote value provided by the Voting API and use it with Rules. Strangely enough, when I checked the tokens available to Rules (which is very comprehensive), I realized that the vote value was not available.

Once I figured out that there is no very easy solution for that, I started to look for the easiest way to overcome that inconvenience and further ones. Custom Token module came to my help.

Use the following code to create a custom token (Type=Node) via the Custom Token module. This will make the vote of the logged-in user be available anywhere the regular tokens are available.

global $user;
$criteria = array('content_type' => 'node', 'content_id' => $node->nid, 'uid' => $user->uid);
$user_vote = votingapi_select_single_vote_value($criteria)/10;
return $user_vote;

Author: (16)


All web developers/designers need to use some tools (I am talking about non-application tools) to make their life easier. Most of these tools are quite famous and they generally depend on Firefox’s add-on system. (e.g. Firebug, Web Developer).

However, there is one other tool that I use quite often and very happy to have. So I decided that it deserves a mention in this blog. It is a javascript bookmarklet called Design by Allan Jardine.

Design features the following components:

  • Grid – overlays a highly configurable layout grid over a web-page. Grid can be set to match any set of dimensions, allowing easy development of CSS layouts in the web-browser.
  • Rule – displays rulers on a page, with all the expected features of the rulers found in a desktop design application, including guides which snap to block display elements and origin location control.
  • Unit – allows measurements to be made between any two points on a web-page, giving basic information about each of the points clicked on, and drawing a line on the page for the measurement.
  • Crosshair – draws a crosshair cursor on the page to assist in layout alignment. Cursor information is also presented in a tooltip.

Author: (16)


One of the best PHP tutorials I’ve ever read

Vikram Vaswani‘s language is clear and his humour is right on cue. Topics ranging from absolute beginner to slightly experienced. Highly recommended.


Author: (16)