modules

api: creating drupal modules

read here about the .info file

More .info files

drupal module example menu hook

Search for: drupal module example menu hook

a possible menu example

Here is API 7 hook menu docs


makesure enable dev modules
remove cache

The following material will walk you through to create a first module

Pick a name: satya_test_module


/sites/all/modules/satya_test_module

satya_test_module.info
satay_test_module.module

core = 7.x
name = Satya Test Module
description = Use this module to muck
version = "7.x-1.0-alpha"

<?php
/**
* @file
* A test module to muck
* Created by Satya.
*/
 
function satya_test_module_help($path, $arg) {
  switch ($path) {
    case "admin/help#satya_test_module":
      return '<p>'.  t("Test module") .'</p>';
      break;
  }
} 
 
function satya_test_module_menu() 
{
  $items['satyatest'] = array(
    'page callback' => 'satya_test_cb1',
    'type' => MENU_CALLBACK,
    'access callback' => TRUE,
  );
 
  return $items;
}
 
function satya_test_cb1()
{
      return t("hello world");
}

Notice the lack of ending tag


structure of a module
a hook to provide help
a hook to provide a menu
a function to respond to the menu

in modules you should see this module listed

if you click help on the module you should see the help text displayed

if you use the url /satyatest you should see a hello world response

should display the hello world

if you see this error most likely you will not drop the drupal cache. You can do this by enabling the devel module.

you should see these when you access the drupal domain where this module is enabled.

go to modules and see your module listed and enable it.

either it is coincidental or designed that way but the help menu on the module screen showed up after I have enabled the module.

for instance i have called the .info file as .inc and it took me a good 10 minutes to see what I was doing wrong

MENU_NORMAL_ITEM: Normal menu items show up in the menu tree and can be moved/hidden by the administrator.

MENU_CALLBACK: Callbacks simply register a path so that the correct information is generated when the path is accessed.

MENU_SUGGESTED_ITEM: Modules may "suggest" menu items that the administrator may enable.

MENU_LOCAL_ACTION: Local actions are menu items that describe actions on the parent item such as adding a new user or block, and are rendered in the action-links list in your theme.

MENU_LOCAL_TASK: Local tasks are menu items that describe different displays of data, and are generally rendered as tabs.

MENU_DEFAULT_LOCAL_TASK: Every set of local tasks should provide one "default" task, which should display the same page as the parent item.

If the "type" element is omitted, MENU_NORMAL_ITEM is assumed.

In drupal how can i control the page title of a menu callback?

Search for: In drupal how can i control the page title of a menu callback?

How to control the page title


drupal_set_title()

More of my notes on the menu module