Creating custom modules

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

This guide includes tutorials and other information that you need to create modules for Drupal 7.

Other helpful resources:

Getting started

Main topic described: module file name and location

Telling Drupal about your module

Main topic described: .info files

Writing module .info files (Drupal 7.x)

Overview

Creating Drupal 7 hooks

The Drupal 7 Hook Concept

Writing comments and implementing your first hook

Drupal hook described: hook_help()

Writing .install files (Drupal 7.x)

This page is about Drupal 7. For Drupal 6, see Writing .install files, (Drupal 6.x).

Declaring the block

Drupal hook described: hook_block_info()

Retrieving data

Main topic described: Database API

Generating block content

Drupal hook described: hook_block_view()

Testing and troubleshooting the module

It's time to enable and fully test your module!

Preparing for a module configuration form

Drupal hook described: hook_menu()

Creating the configuration form

Main topic described: Form API

Validating the data

Main topic described: Form API

Specifying a custom permission for a new page

Drupal hooks described: hook_permission(), hook_menu()

Adapting the query

Main topic described: Database API

Theming the page

Main topic described: Render API

Adding a 'More' link

Main topic described: Block system, Render arrays, Menu system

Testing with SimpleTest

Main topic described: SimpleTest, Assertions

Practicing patches

Main topic described: Git

Show all errors while developing

Set Drupal to show all errors when developing your module.

Drupal 7's code registry

Drupal 7 introduces a code registry - an inventory of all classes and interfaces for all enabled modules and Drupal's core files. The

Exportable configuration

If your module includes data structures that could be considered site configuration, you will probably want to make that data exportable so

Suppress caching (for development) or to use an external page cache

This instruction is for Drupal 7 read about disabling caching in Drupal 8

Using the theme layer (Drupal 7.x)

A well-made Drupal module allows all elements of its presentation to be overridden by the theme of the site on which it is used. In order

Drupal 6/7 programming from an object-oriented perspective

Note: This page is about Drupal 7's (and prior versions') architecture. Drupal 8 changed a great deal and now uses actual OOP practices.

Making your custom data translatable

When developing a module, you should give some consideration to making the text your module displays translatable into other languages. An

Module development HowTos

Drupal 7 module development tutorials.

Understanding the hook system for Drupal modules

A Drupal module is a collection of files containing some functionality and is written in PHP. Because the module code executes within the

Working with multilingual content

As of Drupal 6, the core content translation module enables multilingual content.

Guide maintainers

neerajsingh's picture