[Drupal] How to create a custom module in Drupal 7?
Drupal modules can be defined as a collective set of functions that can be used to create certain features. There are two sets of Drupal modules - 'Contributed modules' and 'custom modules'. Contributed modules are modules that are contributed by Drupal users for general use whereas modules which we create to achieve certain functions are called 'custom' modules. If you want to know how to create a module on your own in Drupal 7, you may read on.
To create a custom module in drupal 7, we require two files :
- .info(meta-data describing the module)
- .module(the module PHP code) file.
The '.info' file contains the information describing the module you have created. In the '.module' file you can write any hooks or related PHP code. The steps to create a custom module in Drupal 7 are given below.
Say, our module's name is Hello.
Step 1: Create a folder called "hello" in sites/all/modules/custom.
Step 2: Inside this folder, create a hello.info file. Make sure that the file name: and folder name is the same. Write the code below inside the hello.info file
name = hello // Name of the module
// The description for the module which will appear in module listing page.
description = Custom Hello module
package = hello
core = 7.x
This will creates a meta-data describing the module
Step 3: Create another file called hello.module in hello directory. Inside the hello.module write the below code
<?php
// $Id: hello.module
/**
* @file
* Custom functions for this site.
*/
In this file we can implement one or more hooks. Now you need go to /admin/build/modules where you will find your hello module. You need to enable the module and finally your custom module has been created. Hope this helps.