Monday, October 19, 2009

Drupal Notes – Modules – Creating the Files

Creating a new Module is as simple as creating a handful of files, as long as you know what to call them and where they should be placed. Oh, and you have to know PHP. Details, details…

If you’ve explored the directory structure of your Drupal installation, you might have found a few directories of interest. Specifically, there’s a modules directory in the root of your Drupal installation, which holds the Drupal core modules. You might have also found the sites/all/modules directory. This is where you want to work when writing and installing custom Modules.

When creating a new Module, there are a handful of standard files that are generated. When you write a new Module, the first thing you do is give it a short but meaningful name. For this example, we’ll use the name “modulename”.

The first time you create a new Module, you’ll need to create some directories in the sites/all/modules directory. In order to make changes and updates to downloaded Modules easier, you’ll probably want to create a custom directory. Then, inside the custom directory, create a directory, named after the Module, for each custom Module you’re creating. So, in our case, we’ll be creating a modulename directory. So we end up with:


Once you get the directories all set up, you’ll create the following basic files:

Readme.txt . . . This file describes what your Module does, just in case someone else has to take over maintenance. . . . This file provides information to the Drupal Core about the new Module. We’ll get more into the use and structure of this file later.

modulename.module . . . This is where the meat of the module will reside. Hooks are implemented here. This is another that we’ll get into in greater detail in a future blog entry. Just know for now that you’ll be spending a lot of time in this file. . . . This file isn’t mandatory, but if you have any kind of configuration in your module, you’ll probably me creating this file. It holds information about administrative forms. Stay tuned for more on this file.

So there really isn’t too much to creating a simple Drupal Module. I’ll get much, much deeper into development in future posts. Keep reading and learn as I do!

No comments:

Post a Comment