Definition

hook_settings()
docs-4-7/hooks/core.php, line 921

Description

Declare administrative settings for a module.

This hook provides an administrative interface for controlling various settings for this module. A menu item for the module under "administration >> settings" will appear in the administrative menu when this hook is implemented.

The form items defined on the settings page will be saved with variable_set(), and can be later retrieved with variable_get(). If you need to store more complicated data (for example, in a separate table), define your own administration page and link to it using hook_menu().

NOTE: if you are using 'checkboxes' or a multiple select, you may wish to include the array_filter element within your form: $form['array_filter'] = array('#type' => 'value', '#value' => TRUE);

Return value

An array containing form items to place on the module settings page.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_settings() {
  $form['example_a'] = array(
    '#type' => 'textfield',
    '#title' => t('Setting A'),
    '#default_value' => variable_get('example_a', 'Default setting'),
    '#size' => 20,
    '#maxlength' => 255,
    '#description' => t('A description of this setting.'),
  );
  $form['example_b'] = array(
    '#type' => 'checkbox',
    '#title' => t('Setting B'),
    '#default_value' => variable_get('example_b', 0),
    '#description' => t('A description of this setting.'),
  );

  return $form;
}
?>