Tutorial and Downloadable Template for Creating a Custom Module in Drupal
October 30, 2014

Introduction

As soon as you start developing reliable websites in Drupal 7, the need to create custom modules arises. There will be plenty of situations where you need to create custom hooks to handle certain business requirements for your Drupal website; and those hooks have to live inside a custom module. For example, check our previous post about preventing content deletion in certain cases in Drupal 7 which implements a custom hook.

Resources on Drupal Custom Module Development

There are plenty of resources online for learning how to create custom modules in Drupal 7. Here are a few of the most notable ones.

  1. A guide for creating Drupal 7.x modules.
  2. Drupal's module developer's guide which has more general concepts.
  3. A guide by Packt Publishing for creating your first module in Drupal 7.

We couldn't however find a quick guide that lists the technical steps required to get a minimal module. This is why we wrote our own. In addition, we're attaching the custom module template to this post for your convenience. The download link is at the end of the tutorial.

Step by Step Custom Drupal 7 Module Creation Guide

Keep in mind we're creating a minimal Drupal 7 module. Basically, as minimal as we can get so that we have a base to start implementing custom PHP code functionality inside the module.

Let's assume your module will be called sk.

  1. Go to your standard Drupal 7 modules directory, which basically is: /sites/all/modules
  2. Create a new directory named sk and then create the below files inside it
  3. Create the file sk.info
  4. Create the file sk.module

Open the sk.info file in a text editor and place the following inside it.

name = SK
description = SOFTKUBE's Custom Drupal Module Template

package = SOFTKUBE
core = 7.x
version = 7.x-1.0

files[] = sk.module

The final step is to activate the module from the Modules admin dashboard. Just login with your admin account, go to the modules administration page, search for your module, and activate it.

Now, all you have to do is write some custom PHP code inside the sk.module file. If you're eager to test something out, check our blog posts about Drupal or, for example, our blog post about conditionally preventing node deletion in Drupal, and you'll surely find some custom hooks to implement inside the sk.module file.

Don't forget to clear Drupal's cache when you implement hooks. Depending on the hook implemented, this might be necessary or optional so keep that in mind.

That's it. Happy coding.

Custom Drupal Module Template Download

Click to Download our Example Custom Drupal 7 Module Template


Drupal Development Open Source Downloads

Share this post


Written by
Mario Awad

Founder of SOFTKUBE, lead developer, and getting things done addict. Passionate about open source, user interface design, business development, and the tech world.

More about Mario Awad


About
SOFTKUBE

A small team of experts developing simple, usable, and high-quality web solutions. We blog about business, entrepreneurship, web development, and technology.

More about us


Recent Posts

Gaining Access to a Legacy Google Apps Account When Phone Verification Fails

Custom Theme Migration from Drupal 9 to Drupal 10

How to Change the Most Recent Git Commit Message

How to Make Google Chrome Forget a Permanent HTTP 301 Redirect

View all posts


All Posts Categories

Business Cheat Sheets CLI Design Development Downloads Drupal Email Google Apps HID Keyboards Multilingualism Open Source Philosophy PHP Pointing Devices Productivity Quotes Science Security SEO Technology Thoughts Windows Zend Framework