Creating a Module (D6)

This example shows how to create a custom module for a site. We typically create one custom catch-all module that we can use for one-off site customizations where we don’t need to create a unique module. If they are general site tweaks that cannot go in template.php, we put them here. Please read the book Pro Drupal Development for a much better understanding of how all of this (and everything else Drupal) works! DrupalBook.com. It is an amazing reference tool for daily usage, as well as a complete walk-through of how to take advantage of the power of Drupal.

Please also visit http://drupal.org/coding-standards if you plan on doing any coding in the Drupal environment (which is what you’re about to do if you read on)! There are very specific style guidelines, and some of them may take getting used to. For example, you must put a space before the { when you write a function (as shown below).

Replace all instances of mymodule with the name of your module. We usually have a catchall module that contains the site name, like amazonmods for example.

Note: You are not limited to one custom module, but it’s probably best to keep “random tweaks” in a single module. If you need to make any more custom modules, be sure to put them in the same “package” (see the .info file) if they’re specific to the site.

  1. Create a directory in sites/all/modules. Name this directory _my_modules.
    * this isn’t required, but makes things clean and easy to find
  2. Create a directory in sites/all/modules/_my_modules. Name the directory mymodule (or whatever you choose for your module name. Do NOT use underscores in your module name. All examples on this site will use mysitemods as the module name unless otherwise noted.
  3. Create a file in the mysitemods directory called mysitemods.info. Use the example below to populate this file.
     
  4. Create a file in the mysite directory called mysitemods.module. Use the example below to populate this file. This will get your module started by creating just a few nodeapi operations. If you use exactly what is shown below, you’ll know if your module is working because when you view anything with this module active, it will show a message on the screen.
Tagged with: , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*