Community Documentation

hook_settings

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.

Return value

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

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);

Related topics

▾ 17 functions implement hook_settings()

aggregator_settings in modules/aggregator.module
Implementation of hook_settings().
blogapi_settings in modules/blogapi.module
contact_admin_settings in modules/contact.module
Settings tab. Using a form rather than hook_settings().
drupal_settings in modules/drupal.module
Implementation of hook_settings().
image_gd_check_settings in includes/image.inc
Verify GD2 settings (that the right version is actually installed).
image_gd_settings in includes/image.inc
Retrieve settings for the GD2 toolkit (not used).
search_settings in modules/search.module
Menu callback; displays the search module settings page.
statistics_settings in modules/statistics.module
Implementation of hook_settings().
system_cron_settings in modules/system.module
Return the cron status and errors for admin/settings.
system_site_settings in modules/system.module
Menu callback; displays a module's settings page.
system_theme_settings in modules/system.module
Menu callback; display theme configuration for entire site and individual themes.
theme_get_settings in includes/theme.inc
Retrieve an associative array containing the settings for a theme.
throttle_settings in modules/throttle.module
Implementation of hook_settings().
unicode_settings in includes/unicode.inc
Return the required Unicode status and errors for admin/settings.
upload_settings in modules/upload.module
user_configure_settings in modules/user.module
_filter_html_settings in modules/filter.module
Settings for the HTML filter.

File

developer/hooks/core.php, line 921
These are the hooks that are invoked by 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;
}
?>
Login or register to post comments