You are here

function domain_settings_form_submit in Domain Access 7.2

Same name and namespace in other branches
  1. 6.2 domain_settings/domain_settings.module \domain_settings_form_submit()
  2. 7.3 domain_settings/domain_settings.module \domain_settings_form_submit()

Submit handler for domain-specific settings.

1 string reference to 'domain_settings_form_submit'
domain_settings_form_alter in domain_settings/domain_settings.module
Implements hook_form_alter()

File

domain_settings/domain_settings.module, line 122
Allows domain-specific use of Drupal system settings forms.

Code

function domain_settings_form_submit($form, &$form_state) {
  $domain_id = $form_state['values']['domain_id'];
  $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;
    }
  }

  // -1 is the primary domain.
  foreach ($values as $name => $value) {

    // Handle checkboxes when array_filter is set. (Do not return empty checkboxes at all.)
    if (is_array($value) && isset($form_state['values']['array_filter'])) {
      $value = array_keys(array_filter($value));
    }
    if ($domain_id == -1 || $domain_id == DOMAIN_SETTINGS_ALL_DOMAINS) {
      variable_set($name, $value);

      // Update the site name of the primary domain, if needed.
      if ($name == 'site_name') {
        variable_set('domain_sitename', $value);
        db_update('domain')
          ->condition('domain_id', 0)
          ->fields(array(
          'sitename' => $form_state['values']['site_name'],
        ))
          ->execute();
      }
      if ($domain_id == DOMAIN_SETTINGS_ALL_DOMAINS) {
        foreach (domain_domains() as $id => $value) {
          domain_conf_variable_delete($id, $name);
        }
      }
    }
    else {
      domain_conf_variable_save($domain_id, $name, $value);
      if ($name == 'site_name') {
        variable_set('domain_sitename', $value);
        db_update('domain')
          ->condition('domain_id', $domain_id)
          ->fields(array(
          'sitename' => $form_state['values']['site_name'],
        ))
          ->execute();
      }
    }
  }

  // Set a message about the affected domains.
  $extra = '';
  if ($domain_id > 0) {
    $domain = domain_lookup($domain_id);
    $affected = $domain['sitename'];
  }
  elseif ($domain_id == -1) {
    $default = domain_default();
    $affected = $default['sitename'];
    $extra = t('These settings will be inherited unless overridden per domain.');
  }
  else {
    $affected = t('all domains');
  }
  drupal_set_message(t('The configuration options have been saved for %domains. !extra', array(
    '%domains' => $affected,
    '!extra' => $extra,
  )));
  module_invoke_all('domain_settings', $domain_id, $form_state['values']);
  cache_clear_all();
}