domain_settings.module
<?php
function domain_settings_perm() {
return array('access domain settings form');
}
function domain_settings_form_alter(&$form, $form_state, $form_id) {
global $_domain;
$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;
}
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();
$format = domain_select_format();
foreach (domain_domains() as $data) {
($data['domain_id'] == 0) ? $key = -1 : $key = $data['domain_id'];
if ($data['valid'] || user_access('access inactive domains')) {
$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]);
}
}
}
function domain_settings_form_submit($form, &$form_state) {
$domain_id = $form_state['values']['domain_id'];
$reset = FALSE;
if ($form_state['values']['op'] == $form_state['values']['reset']) {
$reset = TRUE;
}
$values = array();
foreach ($form_state['values'] as $key => $value) {
if (!in_array($key, array('op', 'submit', 'reset', 'form_build_id', 'form_token', 'form_id', 'domain_id'))) {
$values[$key] = $value;
}
}
foreach ($values as $name => $value) {
if ($domain_id == -1) {
if ($reset) {
variable_del($name);
}
else {
variable_set($name, $value);
}
}
else {
if ($reset) {
domain_conf_variable_delete($domain_id, $name);
}
else {
domain_conf_variable_save($domain_id, $name, $value);
}
}
}
module_invoke_all('domain_settings', $domain_id, $values);
cache_clear_all();
}
function domain_settings_domainform(&$form) {
$form['domain_settings_module'] = array(
'#type' => 'fieldset',
'#title' => t('Domain-specific settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['domain_settings_module']['domain_settings_behavior'] = array(
'#type' => 'radios',
'#title' => t('Domain settings behavior'),
'#options' => array(0 => t('Use the default domain'), 1 => t('Use the active domain')),
'#default_value' => variable_get('domain_settings_behavior', 0),
'#description' => t('Default form value when submitting system settings.')
);
$form['domain_settings_module']['domain_settings_ignore'] = array(
'#type' => 'textarea',
'#title' => t('Disallowed forms'),
'#rows' => 5,
'#cols' => 40,
'#default_value' => variable_get('domain_settings_ignore', ''),
'#description' => t('Disallow domain-specific settings by entering a list of form_ids, one per line.'),
);
}
function domain_settings_disallow() {
static $forms;
if (!isset($forms)) {
$items = array();
$list = trim(variable_get('domain_settings_ignore', ''));
if (!empty($list)) {
$match = preg_replace('/(\r\n?|\n)/', '|', $list);
$items = explode("|", $match);
}
$default = array(
'domain_configure_form',
'system_file_system_settings', 'system_performance_settings', );
$forms = array_merge($default, $items);
}
return $forms;
}
function domain_settings_domain_warnings_alter(&$forms) {
$core_forms = array(
'system_admin_theme_settings',
'system_site_information_settings',
'system_site_maintenance_settings',
'menu_configure',
);
foreach ($core_forms as $form_id) {
if (isset($forms[$form_id])) {
unset($forms[$form_id]);
}
}
}