Drupal Modules


A Drupal module is simply a collection of files containing a set of routines written in PHP. Because the module code executes within the context of the site, it can use all the functions and access all variables and structures of the Drupal Core|main engine.

As of Drupal 5.x, module files should be installed in one of two locations:

  1. /sites/all/modules or
  2. if you run in a multisite configuration, you may want to install the module in a site specific modules directory (e.g. sites/yoursite.com/modules). This way, you can make modules available only for the sites that need them.

As of Drupal 6.x, sites/all/modules is the preferred place for non-core modules and sites/all/themes for non-core themes.

Module files begin with the opening PHP tag <?php. Closing tag ?> is not needed.

Telling Drupal about your module

All modules must have a modulename.info file, which contains meta information about the module. Semicolons are used to comment out a line.


; $Id$
name = Module name
description = A description of what your module does.
core = 6.x


Human readable name.


Short description of the theme. Display at Administer > Site building > themes


Where to find the theme's thumbnail image.


From 6.x all .info files must indicate what major version of Drupal core they are compatible with.

more about info fields
info fields for Drupal 5.x
Structure of the .info file


Allow modules to interact with the Drupal core. A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.

The most common way to tap into Drupal’s core functionality is through th implementation of hooks in modules.


This hook is run at the beginning of the page request. It is typically used to set up global parameters which are needed later in the request. when this hook is called, all modules are already loaded in memory.


This is a hook used by node modules. This hook is required for modules to define one or more node types. It is called to determine the names and the attributes of a module's node types.


This hook can supply permissions that the module defines, so that they can be selected on the user permissions page and used to grant or restrict access to actions the module performs.


This hook allows node modules to limit access to the node types they define.


A Drupal schema is an array structure representing tables and their related keys and indexes. This hook must be in .install file.
Schema API


Drupal's function hook_help() is used for help and additional information about the module.


Verifies a node editing form.

hook_perm Telling Drupal who can use your module

Drupal's hook_perm() specifies what permissions are available for a module. This function just needs to return a list of the permission names this module will use

Install Module

Files name.module and name.info have to be in the right directory on your site.

Module developer's guide



Drupal Modules
Creating Drupal 5.x modules
Creating Drupal 6.x modules

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.