3. Drupal6 Module Development Guide
Topics covered in the presentation
• What is Module
• Collaboration Over Competition
• Telling Drupal About Your
Module
• Hooks
• Block Content
• Other Files
Furqan Razzaq | Drupal Mentor
4. Drupal6 Module Development Guide
What is a Module
A module simply is a collection of procedures that are
logically combined in a group of files.
These procedures can he hooks, menu callbacks,
forms, themes or your custom, or even
jquery/javascript snippets.
Furqan Razzaq | Drupal Mentor
5. Drupal6 Module Development Guide
Kinds of Module
There are three kinds of Drupal Modules
1. Core
2. Contributes
3. Custom
Furqan Razzaq | Drupal Mentor
6. Drupal6 Module Development Guide
Core Modules
• Core modules are the ones that are shipped with Drupal install and
are approved by the core developers and the community.
• The location of these modules is under [installation directory/modules]
• There are also a bunch of include files that these modules use.
Include files are located under [installation directory/includes]
Furqan Razzaq | Drupal Mentor
7. Drupal6 Module Development Guide
Custom Module Development
• Before we start, following are some helpful links to guide you through
the development process:
• http://drupal.org/node/326 [working with Drupal API]
• http://api.drupal.org/api/drupal [Drupal API reference]
• http://drupal.org/node/7765 [Best Practices on creating and maintaining
projects]
• http://drupal.org/coding-standards [coding standards]
• http://drupal.org/writing-secure-code [writing secure code]
We know its a lot to process in one go, but you will get to it eventually.
)
Furqan Razzaq | Drupal Mentor
8. Drupal6 Module Development Guide
Collaboration Over Competition
• Module Duplication is a growing concern with in Drupal community,
which values joining forces on improving one awesome project rather
than building several sub-standard ones that overwhelm end users
with choices.
• So what to do? Search existing modules before you start embarking
on your own quest.
Furqan Razzaq | Drupal Mentor
9. Drupal6 Module Development Guide
Let’s Jump Over Module Development
• So, what do you need:
• Basic PHP knowledge (of course ) including syntax and concept of
PHP Objects
• Basic understanding of database tables, fields, records and SQL
statements
• A working Drupal installation
• Webserver access (in our case, its any set of Apache/PHP/MySql)
Furqan Razzaq | Drupal Mentor
10. Drupal6 Module Development Guide
Let’s Develop a Single Module
• Module Name
• Telling Drupal about your module
• Declaring block content
Furqan Razzaq | Drupal Mentor
11. Drupal6 Module Development Guide
Getting Started
• Create Following files
• .info
• .module
Furqan Razzaq | Drupal Mentor
12. Drupal6 Module Development Guide
Telling Drupal About Your Module
1. How to let Drupal know the module exists?
2. Drupal hook described: hook_help
Furqan Razzaq | Drupal Mentor
13. Drupal6 Module Development Guide
How to Let Drupal Know That Module Exists
• Tell Drupal about your module in modulename.info file. File content
should be like…
• Name (Required) = Color
• Description (Required) = Allows the user to change the color scheme
of certain themes.
• package = Core - optional
• Core (Required) = 6.x
• version = "6.20"
• project = "drupal"
• datestamp = "1292447788"
Furqan Razzaq | Drupal Mentor
14. Drupal6 Module Development Guide
Telling Drupal About Your Module
1. How to let Drupal know the module exists?
2. Drupal hook described: hook_help
Furqan Razzaq | Drupal Mentor
16. Drupal6 Module Development Guide
Apparently Not
• Drupal's module system is based on the concept of "hooks".
• A hook is a PHP function.
• Hooks allow modules to interact with the Drupal core.
• Each hook has a defined set of parameters and a specified result
type.
• A module need simply implement a hook.
Furqan Razzaq | Drupal Mentor
17. Drupal6 Module Development Guide
How to Declare Hooks?
• modulename_hookname()
• color_help()
Furqan Razzaq | Drupal Mentor
18. Drupal6 Module Development Guide
Where/When Hooks are Used?
• Drupal determines which modules implement a hook and calls that
hook in all enabled modules that implement it.
Furqan Razzaq | Drupal Mentor
20. Drupal6 Module Development Guide
Help Hooks – a Module File Entry
/**
* Implementation of hook_help
*/
function modulename_help($path, $arg) {
switch ($path) {
case 'admin/help#color':
$output = '<p>'. t('The color module allows a site administrator to
quickly and easily change the color scheme of certain
themes.’ ).'</p>';
return $output;
}
}
Furqan Razzaq | Drupal Mentor
21. Drupal6 Module Development Guide
Specify the Available Permissions
• Tell Drupal who can use your module.
/**
* Implementation of hook_perm
*/
function modulename_perm() {
return array('access site-wide ', 'administer colors');
}
Furqan Razzaq | Drupal Mentor
22. Drupal6 Module Development Guide
Hook_init ()
• This hook is run at the beginning of the page request.
1. Add CSS or JS that should be present on every page.
2. Set up global parameters which are needed later in the request
Furqan Razzaq | Drupal Mentor
27. Drupal6 Module Development Guide
Hook Menu
• Define menu items and page callbacks.
• This hook enables modules to register paths in order to define how URL
requests are handled.
• This hook is rarely called (for example, when modules are enabled), and
its results are cached in the database.
Furqan Razzaq | Drupal Mentor