Warning message

Documentation is currently being migrated into the new system. Some pages might be temporarily missing, and some guides might appear empty. Thank you for your patience while we are improving Drupal.org documentation.

Creating custom modules

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 comments and implementing your first hook

Drupal hook described: hook_help()

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

Theme function parameter map

This page needs to be deleted, according to original author's comments.

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

Writing module .info files (Drupal 7.x)

Overview

Show all errors while developing

Set Drupal to show all errors when developing your module.

Creating Drupal 7 hooks

The Drupal 7 Hook Concept

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

Writing .install files (Drupal 7.x)

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

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.

Working with multilingual content

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