Drupal Module Development
Open Source CMS
Content Management Systems manage website (or intranet) content Open Source Content Management Systems have become one of the real open source success stories The three most popular open source CMS in the nonprofit sector are:
Joomla Drupal Plone
What does a module do?
Core modules provides functionality Contributed modules extends functionality Custom modules defines new functionality
A Custom module is one which is local to your Drupal Project. It's not yet contributed to the contrib repository
Custom Module(When to write)
You need to answer few questions before writing a Custom Module 1. What do you want to achieve by this custom module? 2. Did you search the Contrib Repository to see if a module is already available for that feature? 3. Have you enabled all possible Configurations of the Core & Contrib module to check if they offer you the feature you require?
If your answer is, Yes, I have done enough research and am sure I have to write the code now, then go ahead ....
Custom Module(Why to write)
I need a new feature which is not yet
available in Drupal, and probably can be contributed as a Contrib Module. I don't want to keep adding additional modules to my site for small tweaks, which I can manage in only one custom module for my website. Don't be too much dependent on Contribs.
Examples of modules
Core required modules:
System, Filter, Node, Block, User
Core optional modules:
Taxonomy, Menu, Comment, Search
3rd party modules:
Views, Panels, CCK, Devel
Hooks
Can be thought of as internal Drupal
events Allow modules to interact with the Drupal core Events include:
Creation, deletion of nodes and users Logging in, logging out
Hooks can also create and alter menus
and forms
Hook examples
hook_user
login, logout, insert, view, update
hook_block
view, save, configure, list
hook_form_alter hook_insert hook_comment
insert, update, view, publish, unpublish
Useful modules/tools
Devel (drupal.org/project/devel) Admin Menu
(drupal.org/project/admin_menu) Drush (drupal.org/project/drush) Any others?
Simple Module Structure
Our first module
Hello World module Two files required for a module:
helloworld.info helloworld.module (Optionally) helloworld.install
helloworld
helloworld.info
helloworld.module
Our first module
Where should I put my module? /path_to_drupal/modules /path_to_drupal/sites/all/modules/
helloworld.info
; $Id$ name = Hello World description = Creates a Hello World Content package = Module Dev Training core = 6.x
helloworld.module
<?php function helloworld_perm() { return array(access content); } function helloworld_menu() { $items[My Module'] = array( 'title' => My First Module', 'page callback' => 'display_helloworld', 'access arguments' => array(access content'), 'type' => MENU_NORMAL_ITEM, ); return $items; } function display_helloworld () { return Welcome to my first Drupal Module helloworld; }
Drupal Module Development
ICT Center
We are making IT happen
Integrity
Commitment
Teamwork