Sadly my first Drupal module isn't one I'll be able to open source for the community. It's been an interesting experience developing it though.
The process of creating a module appears to be quite complex at first, and the online docs aren't all that great at explaining how all of the pieces in the Drupal module API fit together.
After doing some reading and taking a peek at some of the existing Drupal module code, it's not as complicated as it first seems.
Essentially, all you have to do is override a number of Drupal 'hook' functions and provide your own implementation logic to give the module its functionality.
Drupal provides hook functions for all aspects of the module lifecycle - installation, configuration, adding, editing and deletion of content. This makes it easy to write custom installation code which gets executed the first time Drupal discovers the module.
Another other nice touch is that you don't have to write much (or any) module configuration logic. By using the Drupal form API, you can easily build up a web form to capture all of the module configuration settings. Drupal will also magically save and retrieve the settings for you!
The only thing I don't like is that with so many hook functions available, there's quite a lot of potential for code bloat. I had my module up to over 1000 lines of code, relatively quickly. I managed to trim this back substantially in the end.
I haven't come across any modules where any of the code is split up into includes or classes. I don't know whether this is best practice for writing modules, but it would cut down on the amount of code that ends up within the .module file and generally make things easier to manage and maintain.
Now to get my head around writing themes!
2 Comments
[Post comment]
1
Posted by kola | Tuesday 08 May 2007 2:50 AM
If I didn't know better I would say you are enjoying it ;-)
2
Posted by James Netherton | Tuesday 08 May 2007 8:04 AM
Steady on there Kola!
I just added the dBug CFDUMP component, so I'm making eveything more like CF all the time ;-).
From a learning and geeky programming perspective it has been interesting and dare I say it, almost fun!
Not sure what seasoned PHP coders would find of my hackery though :s