Adding a module configuration or settings page to the main Drupal menu is an important task and I like to add a page for each module I build...
Even if it's more of a 'help' page to explain what the module does or how to use it.
Adding one page is fairly simple....
/**
* Impliment hook_menu().
*/
function MY_MODULE_NAME_menu() {
$items = array();
// Configuration Page
$items['admin/config/MY_MODULE_NAME'] = array(
'title' => 'MY MODULE NAME', // Menu item title
'description' => 'Configuration of MY MODULE NAME.', // Menu item description
'access arguments' => array('administer users'), // Specify 'who' can access the page
'page callback' => 'drupal_get_form', // Calls the Drupal Form API
'page arguments' => array('MY_MODULE_NAME_form'), // Pass the function to pass to Form API
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
Note that you'll need the function called in 'page arguments' which can be found here Example of hook_form() and hook_form_submit().
Adding Sub Menus
However, the really interesting feature is the ability to have sub menus and pages that are only available to different roles... See Example of hook_permission() to find out how to set permissions.
Here is an example of a menu item that has one sub, for a settings page, that has a different access level...
/**
* Implementation of hook_menu().
*/
function MY_MODULE_NAME_menu() {
$items = array();
// First Item in the menu
$items['admin/config/MY_MODULE_NAME'] = array(
'title' => 'MY MODULE NAME', // Menu item title
'description' => 'View MY MODULE NAME.', // Menu item description
'access arguments' => array('view MY_MODULE_NAME'), // Specify 'who' can access the page
'page callback' => 'MY_MODULE_NAME_display', // Specify a function to build the page
'type' => MENU_NORMAL_ITEM, // Use 'MENU_NORMAL_ITEM' for the first item
);
// This is an exact duplicate of the above except for the 'type', 'weight' and url,
// which allows another page (settings) to be added as a sub to this one.
$items['admin/config/MY_MODULE_NAME/display'] = array(
'title' => 'MY MODULE NAME', // Menu item title
'description' => 'View MY MODULE NAME.', // Menu item description
'access arguments' => array('view MY_MODULE_NAME'), // Specify 'who' can access the page
'page callback' => 'MY_MODULE_NAME_display', // Specify a function to build the page
'type' => MENU_DEFAULT_LOCAL_TASK, // This allows sub menus from this item.
'weight' => 0, // Weights to help organise the sub menus
);
// This is a sub menu that sits under the above.
// Notice that we have a different access rule so only different roles can view or change the settings.
// Under 'page callback' we are calling the 'drupal_get_form' Form API to handle the settings admin page.
$items['admin/config/MY_MODULE_NAME/settings'] = array(
'title' => 'Settings', // Menu item title
'description' => 'MY MODULE NAME settings.', // Menu item description
'access arguments' => array('administer MY_MODULE_NAME'), // Specify 'who' can access the page
'page callback' => 'drupal_get_form', // Calls the Drupal Form API
'page arguments' => array('MY_MODULE_NAME_admin'), // Pass function to Form API
'file' => 'includes/MY_MODULE_NAME.admin.inc', // You can include a file.
'type' => MENU_LOCAL_TASK, // This makes this a sub.
'weight' => 1, // Use 'weight' to help organise.
);
return $items;
}