A Drupal site can have three kinds of modules (the 3 Cs):
- Core modules that ship with Drupal and are approved by the core developers and the community.
- Contributed modules written by the Drupal community and shared under the same GNU Public License (GPL) as Drupal.
- Custom modules created by the developer – often for a particular use case specific to the site they're working on.
This section of the Developing for Drupal handbook will help you to write your own modules and to collaborate with the community on shared projects.
Before you begin to write your own modules you should also become familiar with the following sections of the Developing for Drupal handbook:
- Working with the Drupal API (Forms, AJAX, Localization, etc.)
- Drupal API Reference
- Maintaining a project on drupal.org
- Drupal coding standards
- Writing secure code
For a collection of useful materials for module developers, see Module Development with Drupal.
Choose a Core System
Once you feel comfortable enough to start digging in, you'll want to identify which version of Drupal you are targeting with your custom module. Individual situations will dictate the choice, but whichever one you choose, it will then dictate the link to the right under "Creating Drupal X modules" that you will then follow, the versions of Drupal core and the examples modules that you will download (git clone), and the version of the api documentation that you will reference once you run out of tutorials and community documentation to follow.
Collaboration over competition
Module duplication is a growing concern within the Drupal community, which values joining forces on improving one awesome project rather than building several sub-standard ones that overwhelm end users with choices. Please remember to search existing modules and themes first before embarking on your quest, and consider whether your project would be better as a feature addition or patch on an existing project. You could save yourself some time, and earn community karma by helping others!
To see sample code for a wide range of APIs, see the Examples project.
The following pages will guide you step-by-step through the creation of modules.