Skip to Content

Custom Drupal Modules

Side tracked once again... sighs.

In this case I find myself in need of a (relatively) simple issue tracking system. Something like Bugzilla is way overkill for me. (For those not in the know, Bugzilla is more or less the standard issue tracking system in the Open Source world.) I've tried the WHUPS system (part of Horde), but find it a little too cumbersome to get set up and integrated with Horde, as well as not quite meeting my needs.

I really just need a list of bugs/issues/tasks I have to do for the projects I'm involved with. Well, that's the key isn't it? First identify my needs. So here they are:

  1. Must handle multiple projects
  2. Must control user access to only authorized projects
  3. Each project can have issues associated with it
  4. Each issue will have a state (reported, in progress, complete, etc.)
  5. Each issue may have one or more progress notes associated with it
  6. States must be configurable (allow additional states, in any order, as needed)
  7. Users may wish to receive email notification when issues meet certain states

In the big picture, this is a basic issues tracking system. What's been missing for me is a tool that integrates into the content management system I use for my websites - Drupal. Because of this, the solutions I've tried break the look and feel of my websites. So, seeing as this is a basic project (er, should only take me a day or so), and I really do need this tool in the long term, AND because I've been wanting to learn how to write a Drupal module, well, what a great opportunity to do so. As an added bonus I can avoid a bunch of user management and login type code.

I will mark my progress on FIFO (this site, just in case you forgot.. ) But this does mean I'm getting a little side tracked from my planned postings on Bash scripting, and learning QT. Never fear though, these are only delayed - not cancelled.

(Side note: There IS a 'project' module available for Drupal. I'm ignoring this on purpose, for three reasons. First, the module did not meet my needs the last time I tried it out. Second, it includes code I'll never use. And three, using it doesn't help us (me) learn how to CREATE a Drupal module. That said, I do see recent activity on it, so I really should give it another shot one day and it might be the perfect tool for your own issue tracking needs.)

So, onto the Drupal Modules. Where to start? Well, it would make sense that you start with a working installation of Drupal. If you've never done this, you might want to try it out. It basically needs a PHP enabled web server, and a MySQL or PostgreSQL database. (I'd recommend MySQL as there is more support for Drupal on MySQL). Next you need some familiarity with installing/configuring a module (see this Drupal page for more detail). Ok, NOW, you have an operational Drupal website. Next let's create our own module.

The first step to creating your own module is to create a directory for it. Whereever you decided to install the Drupal files, you'll have a directory called 'modules' - create a sub directory under here for your own module. In my case I'm tentatively calling my module "issues", so I have a [drupal_directory]/modules/issues directory. Next, create your module file. This is just a standard PHP file, but with a '.module' extension. If you will only ever have the one file for your module, then you don't really need a sub-directory, but it does help to keep your directories clean.

Now that we're set to get our hands dirty with some code. Visit the Module Developers Guide and open up the Creating modules - a tutorial link. This tutorial will not lead you to the whiz-bang module that the world is just dying to have, but it DOES get you started in that direction. It does a solid job of covering the basics. If you are an experienced PHP developer, the lights should be going off as you work through the samples (meaning you should be seeing the potentials). If you are a relative newbie to PHP development, then the guide offers sample code to follow along with the discussion. But you shouldn't be considering a custom module unless you are somewhat comfortable with PHP.

Based on the tutorial, I have a very basic module in place. It's pretty much useless though because I haven't created the database tables yet. I'm getting those done now so that I can expand the module and do something useful (for me) instead of just re-creating the tutorial's sample code.

I'll post the data model I come up with in the next day or so. In the meantime, have fun with your module building!