Drupal 7 develop the custom module.

Drupal is the most popular and secure CMS framework. Drupal is the object-oriented framework and very easy to learn. Today, we will learn about Drupal module. Let’s see how we can create the custom module on Drupal.

I hope you installed the Drupal 7, If not please install it first.

Let’s see we will the Drupal module development step by step.

First of creating the directory with the name of your Drupal module i.e. “thecodingstuff” at the sites/all/modules/ directory.

Then After, create the info file for our module at “sites/all/modules/thecodingstuff/thecodingstuff.info” module directory.

name = TheCodingStuff
description = TheCodingStuff Hello Word Example module
package = thecodingstuff
core = 7.x

We created the module information file with the module name and description about our module and package name or module version.

After, we need to create the module file for our module. we can write Drupal code on module file. So let’s create the module file at “sites/all/modules/thecodingstuff/thecodingstuff.module” module directory.

<?php

function thecodingstuff_menu() {

    $items['thecodingstuff'] = array(
        'title' => 'TheCodingStuff Hello Word!',
        'page callback' => 'thecodingstuff_pagetemp',
        'access callback' => TRUE
    );

    return $items;
}

function thecodingstuff_theme() {
    return array(
        'thecodingstuff_template' => array(
            'variable' => array('article' => NULL),
            'template' => 'thecodingstuff',
        ),
    );
}

function thecodingstuff_pagetemp() {
    $article = "TheCodingStuff - Article Title";
    return theme('thecodingstuff_template',array('article' => $article));
}

 

As per module file, we create the two Drupal hook on our module file first is menu and second is the theme.

Using menu hook we can create the custom route for our module.

Using theme hook we can define the template file of our module.

Now, Let’s create the template file for our module at “sites/all/modules/thecodingstuff/thecodingstuff.tpl.php” template file.

<h1>Hello Word!</h1>
<h2><?php print $article; ?></h2>

After, Complete all the steps please enable our module from the Drupla modules. Then, clear Drupal cache. After clearing cache run our module like.

http://localhost/drupal/thecodingstuff

Run the path of your Drupal with your module route like above. You get output something like this.

Drupal - Hello Word-TheCodingStuff

If you have any question of face any issue after following above steps please write the comment below.

2 thoughts on “Drupal 7 develop the custom module.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s