Create a module configuration (settings) page

(Note: This was done using hook_settings in Drupal 4.7 and is a major change in Drupal 5)

http://drupal.org/node/82967

Comments

Patroleom’s picture

This was really taking a while for me to work, so if you suffer the same problems with the pjirc-5.x-1.1.tar.gz module, here is what I tried and what finally made the settings page appear to me:

1st thing was to add the following part to the pjirc.module:

    $items[] = array(
      'path' => 'admin/settings/pjirc',
      'title' => t(variable_get("pjirc_nav_link", "PJIRC Settings")),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('pjirc_admin_settings'),
      'access' => user_access('access irc'),
      'type' => MENU_NORMAL_ITEM,
      'weight'   => 0);
  

so that it looks like this:

/**
 * Implementation of hook_menu().
 */
function pjirc_menu($may_cache) {
  global $user;
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/settings/pjirc',
      'title' => t(variable_get("pjirc_nav_link", "PJIRC Settings")),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('pjirc_admin_settings'),
      'access' => user_access('access irc'),
      'type' => MENU_NORMAL_ITEM,
      'weight'   => 0);
      
     $items[] = array(
      'path' => 'chat',
      'title' => t(variable_get("pjirc_nav_link", "Chat")),
      'callback' => 'pjirc_page',
      'access' => user_access('access irc'),
      'weight'   => 0);
  }
  return $items;
}

2nd thing were some few corrections to the function admin settings including to rename it to pjirc_admin_settings() to fit the drupal 5 naming standards of functions.

/**
 * Implementation of hook_settings().
 */
function pjirc_admin_settings() {

  $form['pjirc_nav_link'] = array(
    '#type' => 'textfield',
    '#title' => t('Navigation link text'),
    '#default_value' => variable_get('pjirc_nav_link','Chat'),
    ...

    ...
    '#size' => 20,
    '#maxlength' => 255,
    '#description' => t('The IRC room you want to join initially.  Should start with a # (eg: #myroom).'),
  );

  return system_settings_form($form);

}

Now the module provides you with two links:
* http://www.yoursitename.com/pjirc
*http://www.yoursitename.com/admin/settings/pjirc

fbomb’s picture

Assigned: Unassigned » fbomb
Status: Active » Fixed

thanks, I've committed your changes with a slight tweak to match what's in the official drupal doc. I'm creating a new release as we speak.

Anonymous’s picture

Status: Fixed » Closed (fixed)