02. Telling Drupal about your module

Last modified: October 26, 2009 - 20:39

The first function we'll write will tell Drupal information about your module: its name and description. The hook name for this function is 'help', so start with the onthisdate_help function:

<?php
function onthisdate_help($section='') {

}
?>

The $section variable provides context for the help: where in Drupal or the module are we looking for help. The recommended way to process this variable is with a switch statement. You'll see this code pattern in other modules.

<?php
/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function onthisdate_help($section='') {

 
$output = '';

  switch (
$section) {
    case
"admin/modules#description":
     
$output = t("Displays links to nodes created on this date");
      break;
  }

  return
$output;
}
// function onthisdate_help
?>

The admin/modules#description case is used by the Drupal core as the module description on the modules administration page (/admin/modules or ?q=admin/modules).

You will eventually want to add other cases to this switch statement to provide real help messages to the user. In particular, output for "admin/help#onthisdate" will display on the main help page accessed by the admin/help URL for this module (/admin/help or ?q=admin/help).

More information about the help hook:

Download the code so far, (4.7 version) renaming to onthisdate.module before saving in your Drupal installation.

For 5.0

beginner - September 2, 2006 - 17:10
 
 

Drupal is a registered trademark of Dries Buytaert.