Posted on by & filed under Content - Highlights and Reviews, Web Development.

As was discussed in the post, Becoming a Drupal Rockstar, Drupal is a hot technology and now is a good time to start developing in the space. This post will point you in the right direction, and provide you with some Safari Books Online links that you can look to for more detail.

Learning proper Drupal module development can take some time, but if you’re hacking together your first site and tinkering with modules you’ve downloaded, there are a few things that will help you move a lot quicker.

Hooks: Drupal’s secret sauce

First off, you’ll need to know what hooks are. People who are familiar with event driven or aspect oriented programming might recognize the hook system. It’s a way for a module to say, “I’ve gotten to this point in processing, does anyone want to do something before I go further?” Beginning Drupal has a good chapter that covers Drupal hooks.

The module announces this by calling module_implements, module_invoke, or module_invoke all, passing in the name of the hook as the first parameter; for example, module_invoke_all(‘user_logout’, $user).

Other modules can “hook in” and have their code run at that point in code execution by creating a function, called a hook implementation, that uses a particular naming convention. The naming convention is the implementing module’s name followed by the hook_name; for example, if your module were named “foo”, foo_user_logout would do something anytime a user logs out.

Developing from the command line

Using the command line can really speed up your development. With the Drush project, you can do things like download and enable modules, clear the cache, or reinstall your site directly from the command line. Other modules can also provide Drush commands, so check the full list of commands by typing “drush”, and Foundation Drupal 7 has an entire appendix devoted to drush.

Finding bugs

The Devel module suite has a bunch of great tools for developers (see Drupal 7 Module Development for more details). When the Devel module is enabled, you can debug with functions like:

  • dpm which prints a variable to the screen in an easy to read way using the Krumo library.
  • dd which outputs the variable to a file in the temp directory instead of to the screen.
  • dargs which prints the arguments passed to the current function. This can be especially helpful to see what arguments are passed to a hook implementation.

This post should help you get started developing and debugging in Drupal.

Safari Books Online has the content you need

Take a look at some great Drupal resources in Safari Books Online:

The Definitive Guide to Drupal covers every aspect of Drupal, from planning a successful project to making a living from designing Drupal sites, and even to contributing to the Drupal community yourself.
Drupal 7 First Look is written for site administrators, themers, and developers who have some experience with Drupal 6 and want to upgrade their sites, themes, or modules to Drupal 7.
Pro Drupal 7 Development is updated for Drupal 7, covering new essential APIs and improvements in Drupal 7, and teaches you how to write modules ranging from the simple to the complex.

About this author

Lin Clark is a Drupal developer specializing in Linked Data. She contributed to the RDF in Drupal 7 core initiative, created SPARQL Views as part of the 2010 Google Summer of Code, and has spoken extensively about the benefits of using Linked Data technologies in everyday applications. She attended Carnegie Mellon University and is currently pursuing a research Master’s at the Digital Enterprise Research Institute at NUI Galway. More information is available at

Tags: debugging, Drupal, drush, hooks,

Comments are closed.