Getting started with Drupal modules
One of the most important documents I’ve found while learning about Drupal is the node_example module. As it’s name suggests, the node_example module gives a user example code for every aspect of creating a module and a new node type in Drupal. If you’re the type who doesn’t like reading, this could be the chunk of code that fast tracks you to Drupal stardom. What’s more, the good folks at Drupal update node_example for every version of Drupal that comes out. Here’s the one for Drupal 6:
http://api.drupal.org/api/file/developer/examples/node_example.module/6/source
2 Responses to “Getting started with Drupal modules”
Leave a Reply

Jonathan on May 12th, 2009
I’m new to the drupal API
I spent my whole weekend programming a module that defines its own custom content types.
If I’d had known about this node_example page it would have saved me tons of time.
Doing it from scratch I see tons of things I did wrong.
Like not implementing anything to handle node revisions.
It took me hours to figure out why my content type didn’t have the input filter selection box. Only to steal the $form['format'] = form_filter() from node_body_field() because I didn’t understand how to use it, but now I do thanks to this post.
I also spent time writing stupid db_queries when hook_load() should have been used instead.
For new developers I recommend downloading some drupal e-books and learning to use the wonderful examples and documentation on the drupal site.
admin on May 12th, 2009
As a Drupal newcomer, I can give you some advice that I wish someone would have given me when I started with Drupal…
1. Don’t run your own queries. Drupal models data according to it’s own rules. Unless you understand how those rules work, you’re guaranteed to break things by running your own queries. Instead, use Drupal’s data model to add/edit/update data. That means node_load and node_save. Another benefit to using Drupal’s node objects is that you’ll inherit the behaviors of other modules you might install, without having to know about those modules in advance.
2. You’re learning about how to build modules, which is great, and no doubt the right place to start. Very soon, you’ll want to switch it up and move on to modeling your data with CCK (Content) and using modules to manipulate that data. You’ll also want to use modules to manipulate the standard CCK node add forms. My point is… CCK is where it’s at, so don’t waste too much time creating node types the old fashioned way (via Modules)
Happy Drupaling.