Drupal: Creating you Own Custom Module

Tag: Custom Module, Drupal, PHP, Web Design

Drupal is a powerful and flexible tool for both web designers and developers. If you have the time to invest, you can get Drupal to do almost anything. There will come a time when you just can't seem to find a module to fulfill your needs, no matter how hard you try. Don't worry, Drupal is quite simple to customize if you know where to start.

This tutorial will walk you through the process of creating a custom Drupal module. It will cover the basics of the module file structure and requirements. It will also cover the minimal values required within each file. Let's begin.

The first step is to come up with a name for your module. There are a few conventions to follow when choosing a name. The name must begin with a letter, contain only lower case letters and underscores, and must be unique from any other module name used on your site. For the purpose of this tutorial, we will name our module "your_first_module".

Next we need to create a folder to store our module files. We will create our folder in "sites/all/modules".

Inside of the "sites/all/modules" directory create a folder named "your_first_module".

Open the "your_first_module" directory and create two new files. - your_first_module.info, your_first_module.module

We will first work with the your_first_module.info file. This file is a requirement for all modules. It contains meta data needed for the module. Below is an example of the file content. Note: The name, description and core fields are all required.

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

Next open the your_first_module.module file. This file contains the php code that supports our module. This file is also required. Below is an example of the file content. The function provides hook_help() implementation for our module but you can add any custom php code here as needed.

	* Display help and module information
	* @param path which path of the site we're displaying help
	* @param arg array that holds the current path as would be returned from arg() function
	* @return help text for the path
	function your_first_module_help($path, $arg) {
	  $output = ''//declare your output variable
	  switch ($path) {
	    case "admin/help#your_first_module":
	      $output = '<p>'t("Place your first module help text here") .'</p>';
	  return $output;
	} // function your_first_module_help

Save both files and you are done. You can now activate the module by navigating to "/admin/modules". In later discussions we will cover module development in more detail.

Web Hosting:

Web HostingAt Nikkio, we offer full service Web Hosting solutions to our clients. This means we can help you find a home for your new or existing website. A number of hosting options are available to provide the space you need... More

ECommerce Solutions

eCommerce Increases Cash FlowNikkio offers a full range of eCommerce solutions. These solutions are ideal for a broad range of merchants, from those running small entrepreneurial ventures to those managing mature businesses. We can create a custom shopping cart... More

Database Design

database01Whether you have an existing database and need a conversion or want a new one, our database development team has the knowledge and experience to create a database customized to your businesses needs...More

Search Engine Optimization

Creating a beautiful website won’t do your business any good if your potential costumers can’t find it. The internet gives you the potential to reach millions of customers who are actively searching for your products or services... More