Drupal 7: Creating a module (Part – 1)

Drupal is a famous Content Management System used to build web-sites. Drupal allows to extend its functionality by creating modules.

Drupal has its own Core modules and allows users to develop their own modules say Contributed modules and link with them with Drupal.

In this series of articles we are going to steady how to create Drupal modules. Note that these articles are based on Drupal 7 Content Management System.

Step 1. First thing we have to do while creating a module is choose a proper meaningful name to it. Let us say “example” is the module name.

Step 2. Now we need to choose the location where to store this module files.

Drupal uses <Drupal Installed Location>/modules/ directory to store its core modules. Drupal recommends to store custom or contributed modules into <Drupal Installed Location>/sites/all/modules/ directory.

Step 3. Module files must be grouped into a directory name and the name of the directory name must be the name of the module name.

So, in our example, we are creating an “example” module. All its files must be in “example” directory under <Drupal Installed Location>/sites/all/modules/ directory.

Step 4. The first file we are going to create for “example” module is .info file. .info file provides module information eg: module name, description, files used for module et.,

So, our .info file name should be “example.info”.

Step 5. Now place the following text into “example.info” file.

name = Example
description = "An Example Drupal 7 module for CodeSteps.com"
package = Drupal Development - CodeSteps.com
core = 7.x

Each .info file is defined with elements those describes or controls the module.

  • name element is to display the name of the module.
  • description element is the meaningful description about the module.
  • package is to identify in which package the module associated.
  • core element tells us based on what Drupal version the module is developed.

This time we have placed limited information into .info file. We need to update this as we add functionality to our module.

Step 6. Another important file we need to create is .module file. This is the file where we need to write actual logic of our module.

So, name of our module file must be “example.module”.

Now we have created “example.info” and “example.module” files. We have added some information to our “example.info” file and “example.module” file is empty. Yes, we are not yet added anything to our module file “example.module”.

Step 7. Now open modules page in your Drupal based web-site. Observe that our Example module will appear on modules page.

Drupal 7 - Modules page with Example module information

Drupal 7 – Modules page with “Example” module information

Its so simple right? Let us add the functionality to our module in our upcoming articles.


1 comment for “Drupal 7: Creating a module (Part – 1)

Leave a Reply