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.
- Create a directory in sites/all/modules. Name this directory _my_modules.
* this isn’t required, but makes things clean and easy to find - 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.
- Create a file in the mysitemods directory called mysitemods.info. Use the example below to populate this file.
12345; $Id$name = MYSITE general modificationsdescription = General modifications for the MYSITE site.core = 6.xpackage = My Site - 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.
123456789101112131415161718192021<?php// $Id$/*** @file* This is a custom module for the MYSITE site.*//*** Implementation of hook_form_alter()*/function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {switch ($op) {case 'insert':break;case 'update':break;case 'view':drupal_set_message(t('Yes! Our custom module is working.'));break;}}