form_helper.module

<?php
// $Id$

/**
 * @defgroup form_helper Form helper
 *
 * The form_helper.module is collection of modules that assist with form management, validation, and altering.
 *
 * Form helpers sub-modules
 * - form_helper_alter.module
 * - form_helper_fieldset.module
 * - form_helper_validation.module
 */

/**
 * @file
 * A collection of modules that assists with form management, validation, and alteration.
 *
 * This modules contains main administration menu item (admin/settings/form_helper) and some very basic re-usable functions.
 *
 * Form helper sub-modules
 * - form_helper_alter.module
 * - form_helper_fieldset.module
 * - form_helper_validation.module
 */

/**
 * Implementation of hook_menu().
 *
 * Creates the main 'Administer › Site configuration > Form helper' administration page.
 */
function form_helper_menu() {

  $items['admin/settings/form_helper'] = array(
    'title' => 'Form helper',
    'description' => 'A collection of modules that assists with form management, validation, and alteration.',
    'access arguments' => array('administer site configuration'),
    'page callback' => 'module_helper_admin',
    'page arguments' => array('Form helper', 'admin/settings/form_helper'),
    'file' => 'module_helper.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/settings/form_helper/index'] = array(
    'title' => 'Main',
    'access arguments' => array('administer site configuration'),
    'page callback' => 'module_helper_admin',
    'page arguments' => array('Form helper', 'admin/settings/form_helper'),
    'file' => 'module_helper.admin.inc',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -50,
  );

  return $items;
}

/**
 * Set a form elements weight if it is defined.
 */
function form_helper_set_weight(&$form, $start_weight = -50) {
  foreach (array_keys($form['menu']) as $key ) {
    if (strpos($key, '#') !== 0 && !isset($form[$key]['#weight']) ) {
      $form[$key]['#weight'] = $start_weight++;
    }
  }
}