Breaking News
You are here : Home / Drupal / Learning Drupal Module Development Basics

Learning Drupal Module Development Basics

Drupal Module Development Basics :

Hola Amigos! Drupal Module Development is Awesome way to Increse Drupal Functionality also Fulfill our Custom Requirements.So Today i came up with basics of Drupal module development and Tutorial to Build your First Custom Drupal Module.Learning Drupal Module development is quite interesting and whenever you create a module it is very reusable .So lets Get Started and Learn Drupal Module Development Basics.

Drupal Module Development Basics :

Drupal is consider to be machine and Its modules are called its hooks.with every new module added to Drupal means that new Hook has been added to the Drupal.So Whenever We create a new hook and then we’ll attach new hook to our machine called drupal.

A Drupal website possibly can have 3 kind of  modules.

Core modules: The Modules that comes with Drupal Package .These are Approved and tested by drupal community.Like: Blog ,Book ,Forum ,polls are the Core modules of the Drupal which comes with the package.

Contributed modules:These Modules do not come in the package although these are written by the drupal communuty and can be shared under GNU public Licence.Examples of these modules are :Ubercart , css injector etc. The conributed modules resides in “sites/all/modules” .But we can create a folder in named “contrib”  in “sites/all/modules” directory in our fresh install of drupal.After doing this Drupal will install contributed modules to “sites/all/modules/contrib” .

Custom modules: These Modules are created by the developer of the website according to his/her needs.These reside in the “sites/all/modules/custom” . The custom directory does not exist ,we have to create it when we create custom modules in drupal.

Every Time we create a hook or develop  a Drupal Module we Implement it inbuilt hooks, like we wana provide hep for our drupal module named “mymodule” we write like mymodule_help()  ,which implements the hook_help api. dont get confused  I’ll expalin code in 2nd section developing drupal modules .

You can get Refence on Drupal api’s at .The Full functional reference is available there.


Drupal Module Development :

So now We have learned about drupal modules,Now start over to Learn Building our first Drupal module.which is going to be custom module development.

So The Most basic Module must contain two files ,One is “info” file and other is “module” file.

  • info :Contains the Information about the Drupal Module.
  • Module:Contains the whole logic and implementation of the module.

So from here we gonna start creating our new custom drupal Module,we’ll be calling it mymodule.So i want you to create a directory named “mymodule” in custom folder,So we end up like this Structure:-  “sites/all/modules/custom/mymodule” . Lets Create our module Files now.

Drupal Module Development::Module Info File

Now In our “mymodule” Folder we’ll create info file which will have information about our module.The file name will be . module information file)


name = My Module
description = My first module in drupal7.
core = 7.x
package = PR
version = "7.x"


The nams is the name of the drupal module and .description is the description about the module.The Core is the version if the Drupal for which your are writing module.Package is kind of category in which your module falls.The version is generally written by drupal community when you submit module to drupal community ,but you can write your own if you are creating it for yourself.

Drupal Module Development::Module  File

Now we have created our module’s information now we develop our first drupal custom module,so we move further to write module file.module fiel have .module extension.So the file we create is mymodule.module . The Module file implements the various Drupal hooks ,,like permissions ,menu’s etc.[highlight bg=”#DDFF99″ color=”#000000″]Also module file is a php file with extension .module which has open php tag(<?php) but not end(?>) tag.So it should be kept in mind that you should not write end php(?>) tag.[/highlight]

So Here is the Module File:

mymodule.module(Drupal Module File)

As you see this is simple php file that contain fucntions.But you might not understand how it works.So we’ll go through each of the function and i’ll try to define working of each function.

Drupal Module Development::Function Description

So at very First we take a look at function mymodule_menu .This module Implements the hook_menu . This will simply create a new menu link and corresponding to that link a page and finally return them in form of array.The Function Following is creating a Two menu links simple_page and secure_page. simple_page is accessible by every one .But the secure_page is only accessible by the admins only.

Callback Functions:

page callback functions are called for each of the menu hook defined.They return content which is printed on the screen.

Permission Function:

Implements drupal’s hook_permission .which handles the permission.It may be noted that single permission hook can be used for all of the pages ,menus we create.

Help Function (help hook):

Implements hook_help .which is generally used for help regarding module you are writing .This function returns a output ,which is generally a help content.

That was all for drupal custom module development .I think from this you should be able to create a very simple and basic first module of drupal.

Now just enable your module from drupal admin panel.

Drupal module development

Drupal module

Now You visit

http://localhost/yourdrupalprojectname/simple_page ,


You’ll see your module output at above addresses.

[jbutton icon=”download” size=”xlarge” link=””]Download Sample Module[/jbutton]

Thanks for visiting .please hit like ,share if you liked this post.


Tags : , , ,

2 Replies

  1. Olivia Brown says:

    Very nice post. Thanks for sharing.

Leave a Reply

Want to join the discussion ? Feel Free to contribute !