Creating your own Drupal Module

This is still in alpha mode.. I never really had to create my own module, so I couldn't continue with this tutorial.. I hope someone will help one day.

=Easy!=

Alright, maybe not.. But here is a brief summary of some of the the endless docs you'll have to read from drupal.org.

Simple Module
Basically, Drupal's modules are full of hooks, which are functions that do what drupal wants them to do, with the ability for you to override the default ones and create your own ones without touching the original code. Here is a list of some of the hooks used in Drupal.

How do you do so? with modules.

@TODO xushi: instead of random function examples, let's try using them all to make one big module in the end.

_init
The _init hook initialises the module, sets up the global variables, and is the first hook (function) to be executed in your .module file. To create a very simple module, just add your code into a mystuff_init {...} function and save it as mystuff.module. So, as an example,

file: xushitest.module /** * Implementation of hook_init. */ function xushitest_init { print 'hello!'; }

The following in theory would print out 'hello', however, more functions (discussed later) will need to be created to tell it where to display it, and what to do.

Definition
The _help hook creates user documentation and passes it to either the engine or other modules. This documentation will be displayed by the user when she clicks on the Help button in your Drupal site.

Note: This module should only be used for user help. Any documentation you want to give for developers, keep them within the code and/or module file(s) as discussed in the Commenting your Code section.

Parameters
So.. moving on. This module has a parameter $section. It basically asks for which section of help it needs. There are different examples of sections. Here are some,

admin/modules#description - The description found on the admin/modules page.

admin/help#modulename - The module's help text, displayed on the admin/help page and through the module's individual help link.

Return value
So, now that you got the parameters, all that's needed is to return your values. You can do that in a switch case like so,

function xushitest_help($section) { switch ($section) {

case 'admin/help#block': return t(' Blocks are the boxes visible in the sidebar(s)       of your web site. These are usually generated automatically by        modules (e.g. recent forum topics), but you can also create your        own blocks using either static HTML or dynamic PHP content. '); break;

case 'admin/modules#description': return t('Controls the boxes that are displayed around the main content.'); break; } }

Notice you return your content enclised in a t function. This is the translation function that automatically translates your text.