Community Documentation

Tools, tips and tricks

Last updated February 21, 2013. Created by NancyDru on November 3, 2007.
Edited by dumbass, drupalshrek, LeeHunter, add1sun. Log in to edit this page.

Handy modules

The Devel, Devel_FormInspect, and Coder modules are great tools to help with development work.

Drush

If you are anything more than a casual site builder then you really should be using Drush. For those coming from a design/visual background working on the command line can seem a little intimidating but it is really very simple and the efficiency and power it offers is huge. From everyday clearing of caches through to complex management of features Drush manages tasks which can take hours in minutes.

Develop on a Page

If I'm adding something very new to my module, I often develop it first in a PHP page on one of my test sites - it's just easier and potentially less disruptive. I still follow the same development "rules" - only the environment is different. If it doesn't work out, it's much easier, emotionally, to throw away a single page than stuff that's already in a module.

Package

In the early stages of development, I find it useful to include a line in the ".info" file that reads:

package = zzz

This puts my module at the very end of the modules list where I can reach it quickly (CTRL+END) to enable/disable it.

hook_enable / hook_disable

These hooks are often overlooked but I find them useful:

  1. Set/reset all your variables to their defaults in this function for an easy way back to an almost-virgin state and to make sure the defaults only have to be correct in one place.
  2. Provide a message that will direct your users to the settings page.
  3. Log the userid of the enabling/disabling user.

hook_help

It's always a good idea to help the end-user, so at least start with a skeleton hook_help. It can be filled in more completely as you go along.

hook_menu

It's a rare module that doesn't have at least one menu item, so go ahead and start with a skeleton for this.

hook_uninstall

Even if you didn't create any tables or content types that should be cleaned up, I can pretty much guarantee that you used some variables (i.e. variable_get, variable_set). Delete them. If you created blocks, it's a good idea to clean those up too. Don't forget to test it.

To do list

Invariably you will think of something that needs to be done sooner or later. Put a small comment section at the top of your module for including these notes.

Comments

Module Builder

Another helpful module is Module Builder, which generates starter modules, an idea similar to starter themes such as Zen, etc.

Drush

I recently stumbled upon Drush and now use its cli for enabling disabling modules (to check that the schema specified in .install are getting created/destroyed).

Its so much easier to just type en [mod_name] than to go to administer/modules then scroll down to your module and enable and wait for it.

Offcourse drush can be used for so much more.

Happy coding!