You are here

function domain_theme_settings_submit in Domain Access 7.3

Same name and namespace in other branches
  1. 6.2 domain_theme/domain_theme.admin.inc \domain_theme_settings_submit()
  2. 7.2 domain_theme/domain_theme.admin.inc \domain_theme_settings_submit()

Process domain_theme_settings form submissions.

1 string reference to 'domain_theme_settings_submit'
domain_theme_form_alter in domain_theme/domain_theme.module
Implements hook_form_alter().

File

domain_theme/domain_theme.admin.inc, line 269
Include file to handle theme configuration screen

Code

function domain_theme_settings_submit($form, &$form_state) {
  $values = $form_state['values'];

  // Prepare a filepath for color module settings.
  $domain = domain_lookup($values['domain_id']);

  // We aren't using $filepath in Drupal 7; this can probably be removed.
  $filepath = file_default_scheme() . ':/' . '/domain-' . $domain['domain_id'];
  $vars = array(
    'palette',
    'stylesheets',
    'logo',
    'files',
    'screenshot',
  );
  foreach ($vars as $variable) {
    $preset = variable_get('color_' . $values['theme'] . '_' . $variable, '');
    if (!empty($preset)) {
      $values['color_' . $values['theme'] . '_' . $variable] = $preset;
    }
  }

  // If our domain uses different schemes, we have to ensure that the {variable} table stays accurate
  // for the primary domain.
  if (isset($values['domain_color_defaults'])) {
    foreach ($values['domain_color_defaults'] as $key => $value) {
      if (!empty($value)) {
        variable_set($key, domain_unserialize($value));
      }
      else {
        variable_del($key);
      }
    }
  }

  // Set the filepath for color module.
  if (!empty($values['color_' . $values['theme'] . '_stylesheets'][0])) {
    $filepath = domain_theme_get_color_path($values['color_' . $values['theme'] . '_stylesheets'][0]);
  }

  // Deal with file uploads.
  domain_theme_file_upload($values);

  // Set the variables for saving.
  $key = $values['var'];
  $domain_id = $values['domain_id'];
  $theme = $values['theme'];

  // Exclude unnecessary elements before saving.
  unset($values['var'], $values['submit'], $values['reset'], $values['form_id'], $values['op'], $values['form_build_id'], $values['form_token'], $values['domain_id'], $values['domain_color'], $values['domain_color_defaults']);
  $settings = serialize($values);

  // Insert or Update?
  // This lookup returns -1 on failure.
  $check = domain_theme_lookup($domain_id, $theme);

  // Update.
  if ($check != -1) {
    db_update('domain_theme')
      ->fields(array(
      'settings' => $settings,
      'filepath' => $filepath,
    ))
      ->condition('domain_id', $domain_id)
      ->condition('theme', $theme)
      ->execute();
  }
  else {
    db_insert('domain_theme')
      ->fields(array(
      'domain_id' => $domain_id,
      'theme' => $theme,
      'settings' => $settings,
      'status' => 0,
      'filepath' => $filepath,
    ))
      ->execute();
  }

  // If nothing is active, then we make this one active.
  $active = db_query("SELECT COUNT(domain_id) FROM {domain_theme} WHERE domain_id = :domain_id AND status = 1", array(
    ':domain_id' => $domain_id,
  ))
    ->fetchField();
  if (empty($active)) {
    db_update('domain_theme')
      ->fields(array(
      'status' => 1,
    ))
      ->condition('domain_id', $domain_id)
      ->condition('theme', $theme)
      ->execute();
    drupal_set_message(t('%theme has been set as the default theme for %domain', array(
      '%theme' => $theme,
      '%domain' => $domain['sitename'],
    )));
  }

  // Clear the cache.
  cache_clear_all();

  // Finish processing the form.
  drupal_set_message(t('The configuration options have been saved.'));
  $form_state['redirect'] = 'admin/structure/domain/view/' . $domain_id . '/theme';
}