I’ve learned quite a bit about how Drupal works with styles and how pages are rendered. Now I’m looking at how to build modules. What I would like to do is create a few custom modules that can “suck in” and combine information from other sources into a master feed – a feed aggregator on steroids. Similar to a “mashup” server of some kind. This is still a little fuzzy in my mind, but my intent is to look at ways to process and combine data streams from various sources into a “master view”.
As an example if I’m interested in the Saab Turbo-X then I would want to combine data feeds from enthusiast sources, Saab, GM, and a number of other places into a “master view” so that on one page I would have everything that I need to know about this car.
So with this in mind I embark on my trip down “module lane”. I can already see there are a few bends in the road, but before we go there, drupal.org has a great tutorial on module development so you should read this. There’s also a good section on setting up a development environment. For my development environment I’m running on Windows XP Pro, Apache 2.2.8, MySQL 5.x, PHP 5.2.5, and Drupal 6.2. For my actual development tool I am using the very latest Aptana Studio Community Edition – my current rev is 1.1.6.009905.
You should focus on the links above to start – as with my previous articles on Drupal I am not seeking to replace their excellent documentation, but really provide a “newbie” spin on how to get going. I’m not a PHP expert (but I sure am getting there…) and I would not call myself a Drupal guru either.
Using Drupal’s tutorial I was able to easily create a module and get it working, but I did have a few issues:
- The “.module” thing without a “.php” ending needs to get configured in your IDE too as a PHP file.
- There are some subtle differences in the .info files that can cause confusion with earlier versions of drupal, for example the dependencies key/value is now an array type. To add multiple dependencies you need to add these to the array one at a time.
- It is not entirely clear how to enable IDEs to recognize core Drupal libraries and functions so that “intellisense” lookup stuff works. Check this out for Aptana.
- CVS stinks…I use SVN…so I naturally don’t like posting anything to Drupal’s code managemnet system. You can get a decent CVS GUI client from tigris.org (the same people that make svn and tortoise).
I learned a few things that are very important when building modules:
- When you are building modules it is very important to not put any HTML formatting directly in the code. Use CSS tags and DIVs or your users will have fits trying to get things working especially if you are creating block type modules.
- Think of all the possible variables in your module and build an administration interface to make your module as flexible as possible.
- If things are not showing up and you can’t see any cause, disable and re-enable your module. Clear your cache. Turn off all caching and performance stuff in the administration interface.
- PHP (not really Druapl per se) has some interesting operators like “.=” that are used quite a bit in code and examples. You need to learn these or at least have a handy cheat sheet. “.=” is roughly equivalent to an “append” function in other languages
- Drupal then adds confusion a bit with some functions like “t()” and “l()“. These are important to know and understand, but they really should have decent names. Once you are up to speed on these it is ok.
Building modules in Drupal is pretty simple I think. What it takes is a decent IDE (aptana), a good understanding of PHP syntax, and some time studying the Drupal APIs. I’m going to work on a real world example in my next modules post. I’m also going to look at CCK and Views and examine if I can use these instead of a module.