domain_settings_form_alter(&$form, $form_state, $form_id)Implement hook_form_alter()
This function checks the #submit value of the form to see if system_settings_form() has been invoked. If so, we may attach domain-specific settings to the form, if the user is permitted to use this module and the form is not on the administrator's denied list.
domain_settings/domain_settings.module, line 25
<?php
function domain_settings_form_alter(&$form, $form_state, $form_id) {
global $_domain;
// Remove settings that cannot be used reliably.
$disallow = domain_settings_disallow();
if (!user_access('access domain settings form') || in_array($form_id, $disallow) || !isset($form['#submit']) || !in_array('system_settings_form_submit', $form['#submit'])) {
return;
}
// Set our drop down's weight to be one lighter than the submit button's,
// ensuring that it always appears right above it (assuming nobody else
// form_alter()s us out.)
drupal_set_message(t('This form is domain-sensitive, be sure you select the proper domain before saving.'), 'warning', FALSE);
$weight = isset($form['buttons']['#weight']) ? $form['buttons']['#weight'] : 0;
$form['buttons']['#weight'] = $weight + 2;
$domain_weight = $weight + 1;
$form['#submit'][] = 'domain_settings_form_submit';
$options = array();
// Get the display format of the form element.
$format = domain_select_format();
foreach (domain_domains() as $data) {
// Cannot pass zero in checkboxes.
($data['domain_id'] == 0) ? $key = -1 : $key = $data['domain_id'];
// The domain must be valid.
if ($data['valid'] || user_access('access inactive domains')) {
// Checkboxes must be filtered, select listts should not.
$options[$key] = empty($format) ? check_plain($data['sitename']) : $data['sitename'];
}
}
$form['domain_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Domain-specific settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => $domain_weight,
);
$default = $_domain['domain_id'];
if (!variable_get('domain_settings_behavior', 0) || $default == 0) {
$default = -1;
}
$form['domain_settings']['domain_id'] = array(
'#type' => empty($format) ? 'radios' : 'select',
'#title' => t('Save settings for'),
'#options' => $options,
'#required' => TRUE,
'#description' => t('Select the domain to which these settings apply.'),
'#default_value' => $default,
);
if ($format) {
$form['domain_settings']['domain_id']['#multiple'] = FALSE;
$form['domain_settings']['domain_id']['#size'] = count($options) > 10 ? 10 : count($options);
}
foreach ($form['#submit'] as $key => $value) {
if ($value == 'system_settings_form_submit') {
unset($form['#submit'][$key]);
}
}
}
?>