This site is archived.
Skip to Content

Make a Module: A Hands-on Intro to Module Development

Your session in a few words: 
Learn to build Drupal 6 modules
Date: 
September 3, 2009 - 13:40 - 14:30
Room: 
Gulbenkian
Track: 
From zero to hero
Session Type: 
Lecture
Level of expertise: 
Beginner
Language: 
English

Interested in learning how to develop a custom Drupal module? This is a practical session designed to introduce you to module development.

Get hands-on. Bring your laptop and build your own module as we go. (Of course, you're welcome to just listen.)

We will cover:

  • Basic module architecture
  • .info files and .module files
  • Using hooks
  • Using existing Drupal APIs
  • Finding documentation
  • Debugging
  • Installing and uninstalling

By the end of this session, we will have created a functional module.

Prerequisites:

  • Some Drupal knowledge
  • Some PHP knowledge

If you want to write your own module as you go, you will need a laptop with...

  • A text editor or PHP IDE.
  • A Drupal install that you can access easily. I suggest a local copy running on your laptop.

The code from the presentation

In the presentation, I showed a .info file and a .module file. Here they are.

paris.info

;$Id$

name = Paris
;package = paris
description = Example of how to build modules.
core = 6.x
php = 5.2
;dependencies[] = autoload

Update: To see the PHP code with syntax highlighting, see this DrupalBin entry: http://drupalbin.com/11276

paris.module

<?php
// $Id$

/**
* The main file for paris.
* @file
*/

/**
* Implementation of hook_help().
*/
function paris_help($path, $args) {
if ($path == 'admin/help#paris') {
return t('This is an %foo example !another module.',
array('%foo' => 'extra-cool', '!another' => 'test'));
}
}

/**
* Implementation of hook_block().
*/
function paris_block($op = 'list', $delta = 0, $edit = NULL) {
switch ($op) {
case 'list':
// Declare names of deltas: $blocks['delta'] = array()
$blocks['paris_block'] = array(
'info' => t('Paris Block'),
);
$blocks['paris_block2'] = array(
'info' => t('Paris Block2'),
);
return $blocks;
case 'view':
// Create content. Usually, this will use $delta.
if($delta == 'paris_block') {
$block['subject'] = t('Subject');
$block['content'] = t('Op: %op, Delta: %delta',
array('%op' => $op, '%delta' => $delta));
}
elseif ($delta == 'paris_block2') {
$block['subject'] = t('Kittens are cute');
$block['content'] = t('Hi');
}

return $block;
}
}

For a much more elaborate example of the block code, you can take a look at the book Learning Durpal 6 Module Development.

could not get Paris module to work

Hi Matt, thank you for the files you used in class.
I installed them on my local machine version of Drupal and they were not recognized.
I have successfully installed several other modules in the >sites>all folder but for some reason the Paris module never shows up in the module list on my admin page.

I am running a macbook unibody with OS X with no special tweaks.

Any ideas of simple things that could cause this problem?