User login

Form at a tab in administration section, Drupal 5

The shortcut:

In implementation of hook_menu, may_cache section...

function cmt_menu($may_cache) {
  $items = array();
  if ($may_cache) {
//...
    $items[] = array(
      'access'             => user_access('administer community managed taxonomy'),
      'callback'           => 'drupal_get_form',
      'callback arguments' => array('cmt_settings_form'),
      'description'        => t('Configure Community-managed Taxonomy options that apply to all vocabularies with these settings.'),
      'path'               => 'admin/content/cmt/settings',
      'title'              => t('Settings'),
      'type'               => MENU_LOCAL_TASK,
    );
// ...
  }
  return $items;
}

Directly calls:

/**
* Configures Community Managed Taxonomy site-wide options.
*/
function cmt_settings_form() {
  $form = array();
// ...
  return $form;
}

(Or even use system_settings_form instead of drupal_get_form if only saving your settings as straightforward variable_set options, and you can leave off the submit buttons and the submit handler and Drupal takes care of saving the variables for you.)

If you have or expect to have multiple tabs, Agaric expects user.module's callback function makes more sense. This is how I walked backwards through the core module to see how premium Drupal does things:

In implementation of hook_menu, may_cache section:

   $items[] = array('path' => 'admin/user/user/create', 'title' => t('Add user'),
      'callback' => 'user_admin', 'callback arguments' => array('create'), 'access' => $admin_access,
      'type' => MENU_LOCAL_TASK);

Find the function user_admin(...). Here it is with the irrelevant parts cut out:

function user_admin($callback_arg = '') {
  $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
  switch ($op) {
// ...
    case t('Create new account'):
    case 'create':
      $output = drupal_get_form('user_register');
      break;
    default:
// ...
  }
  return $output;
}

So, find the function user_register()

And here's the part I was interested in. Stripped to slightly less than its essentials, user_register creates a form array and returns it:

function user_register() {
  $form = array();
// ...
  $form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
  return $form;
}

This tutorial is inspired by the my doing something wrong to result, first, in a menu_callback error and, after resetting the menus to default with devel (Note to self: next time, use clear cache to clear the menu cache) actually crashing httpd on the test environment in my computer.

I took this as an indication that I might possibly be doing something wrong, and followed the clearest example of a subsidiary administration form that I could find, from the user module. Turns out I was calling the function from inside itself instead of just returning $form, and that was the only fix I needed.

The shortcut:

In implementation of hook_menu, may_cache section...

function cmt_menu($may_cache) {
  $items = array();
  if ($may_cache) {
//...
    $items[] = array(
      'access'             => user_access('administer community managed taxonomy'),
      'callback'           => 'drupal_get_form',
      'callback arguments' => array('cmt_settings_form'),
      'description'        => t('Configure Community-managed Taxonomy options that apply to all vocabularies with these settings.'),
      'path'               => 'admin/content/cmt/settings',
      'title'              => t('Settings'),
      'type'               => MENU_LOCAL_TASK,
    );
// ...
  }
  return $items;
}

Directly calls:

/**
* Configures Community Managed Taxonomy site-wide options.
*/
function cmt_settings_form() {
  $form = array();
// ...
  return $form;
}

(Or even use system_settings_form instead of drupal_get_form if only saving your settings as straightforward variable_set options, and you can leave off the submit buttons and the submit handler and Drupal takes care of saving the variables for you.)

If you have or expect to have multiple tabs, Agaric expects user.module's callback function makes more sense. This is how I walked backwards through the core module to see how premium Drupal does things:

In implementation of hook_menu, may_cache section:

   $items[] = array('path' => 'admin/user/user/create', 'title' => t('Add user'),
      'callback' => 'user_admin', 'callback arguments' => array('create'), 'access' => $admin_access,
      'type' => MENU_LOCAL_TASK);

Find the function user_admin(...). Here it is with the irrelevant parts cut out:

function user_admin($callback_arg = '') {
  $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
  switch ($op) {
// ...
    case t('Create new account'):
    case 'create':
      $output = drupal_get_form('user_register');
      break;
    default:
// ...
  }
  return $output;
}

So, find the function user_register()

And here's the part I was interested in. Stripped to slightly less than its essentials, user_register creates a form array and returns it:

function user_register() {
  $form = array();
// ...
  $form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
  return $form;
}

This tutorial is inspired by the my doing something wrong to result, first, in a menu_callback error and, after resetting the menus to default with devel (Note to self: next time, use clear cache to clear the menu cache) actually crashing httpd on the test environment in my computer.

I took this as an indication that I might possibly be doing something wrong, and followed the clearest example of a subsidiary administration form that I could find, from the user module. Turns out I was calling the function from inside itself instead of just returning $form, and that was the only fix I needed.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.