Add fields to the Site information section on Drupal 6.12
-
15-04-2021 - |
Domanda
I've been shifting through the drupal documentation and forums but it's all a little daunting. If anyone has a simple or straight forward method for adding fields to the Site information page in the administration section i'd really appreciate it.
As a background, i'm just trying to add user customizable fields site wide fields/values.
Soluzione
In a custom module, you can use hook_form_alter()
to add extra fields to that form. For example:
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'system_site_information_settings') {
$form['my_module_extra_setting'] = array(
'#type' => 'checkbox',
'#title' => t('Use my setting'),
'#default_value' => variable_get('my_module_extra_setting', TRUE),
);
}
}
Anywhere in your code you need access to the saved setting itself, you can use the same call that's used to populate that form element's default value: variable_get('my_module_extra_setting', TRUE)
Altri suggerimenti
In order to save the value from your new custom field you will need to add a second submit item to the submit array eg:
$form['#submit'][] = 'misc_system_settings_form_submit';
and then add a function to handle the submission, eg:
function misc_system_settings_form_submit($form_id, $form_values) {
// Handle saving of custom data here
variable_set('access_denied_message', $form_values['values']['custom_access_denied_message']);
}
The function should be mymodule_form_alter instead of mymodule_hook_form_alter