How to write a module for Drupal

Two things I highly recommend before you start

  1. Download the (free) program called NotePad++ (pronounced Notepad Plus Plus)
    • There are too many reasons to list, but it makes a world of difference.
  2. Or don't. Suit yourself.

Assuming you did not¹ take my advice (or even if you did), let's get started.

First, create a new folder and name it whatever_you_will_name_your_module (lowercase letters and underscores only -- no numbers, hyphens, dashes, slashes, periods, dots, commas, tildes, ampersands, etc. In fact, if possible, avoid the underscores too). The example module name whatever_you_will_name_your_module is a bad example, actually. It's too long, it uses underscores, and it just plain sucks to write over and over. So I'll assume your module is named mymodule instead, which means you should now have a new, empty folder on your desktop (or wherever you want to put it) called mymodule. Moving on.

Next, open Notepad (not to be confused with Wordpad -- big difference). On the first line, type this:

; $Id$

Below that, add the following:

name = My Module
description = Describe whatever it is that your module does in a single sentence.
core = 6.x

Now:

  1. Click File » Save
  2. Make sure you're saving it in the mymodule folder you just created
  3. Where it says Save as type: Text Documents (*.txt) change Text Documents (*.txt) to All Files (*.*)
  4. Where it says Encoding: ANSI change ANSI to Unicode
  5. Next to Filename: type mymodule.info
  6. Click Save

You should now have a file named mymodule.info inside a folder named mymodule and the file (mymodule.info) should look like this:

; $Id$
name = My Module
description = Describe whatever it is that your module does in a single sentence.
core = 6.x

That does it for step one. At minimum, your module will have two files:

  • A .info file (already did that part), and
  • A .module file

¹ One of the differences between using Notepad and NPP is that with Notepad does not have syntax highlighting; NPP does.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.