You are here

function spaces_system_settings_form_submit in Spaces 6.3

Same name and namespace in other branches
  1. 7.3 spaces.overrides.inc \spaces_system_settings_form_submit()
  2. 7 spaces.overrides.inc \spaces_system_settings_form_submit()

Form submit handler for system settings form for space-specific overrides. Similar to system_settings_form_submit() but saves override values to space.

1 string reference to 'spaces_system_settings_form_submit'
spaces_form_alter in ./spaces.overrides.inc
Implementation of hook_form_alter().

File

./spaces.overrides.inc, line 138

Code

function spaces_system_settings_form_submit($form, &$form_state) {
  if ($space = spaces_get_space()) {
    $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';

    // Exclude unnecessary elements.
    unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['preset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
    if ($preset = $space->controllers->variable
      ->get('spaces_preset_' . $space->type)) {
      $preset = spaces_preset_load($preset, $space->type);
    }
    foreach ($form_state['values'] as $key => $value) {
      if ($op == t('Reset to defaults')) {

        // variable_del($key);
        $space->controllers->variable
          ->del($key);
      }
      elseif ($preset && $op == t('Save to @title', array(
        '@title' => $preset->title,
      ))) {
        $space->controllers->variable
          ->del($key);
        $preset->value['variable'][$key] = $value;
      }
      else {
        if (is_array($value) && isset($form_state['values']['array_filter'])) {
          $value = array_keys(array_filter($value));
        }

        // variable_set($key, $value);
        // @TODO: Implement selective saving -- e.g. only save if
        // differs from parent value (preset first, then check original).
        $space->controllers->variable
          ->set($key, $value);
      }
    }
    if ($op == t('Reset to defaults')) {
      drupal_set_message(t('The configuration options have been reset to their default values for %space.', array(
        '%space' => $space
          ->title(),
      )));
    }
    elseif ($preset && $op == t('Save to @title', array(
      '@title' => $preset->title,
    ))) {
      drupal_set_message(t('The configuration options have been saved for %title.', array(
        '%title' => $preset->title,
      )));
      spaces_preset_save($preset);
    }
    else {
      drupal_set_message(t('The configuration options have been saved for %space.', array(
        '%space' => $space
          ->title(),
      )));
    }
  }
}