You are here

function spaces_overrides_preset_save in Spaces 7

Same name and namespace in other branches
  1. 6.3 spaces.admin.inc \spaces_overrides_preset_save()
  2. 7.3 spaces.admin.inc \spaces_overrides_preset_save()

Submit handler for saving overrides to a preset.

1 string reference to 'spaces_overrides_preset_save'
spaces_overrides_form in ./spaces.admin.inc
Form for managing space override values.

File

./spaces.admin.inc, line 202

Code

function spaces_overrides_preset_save(&$form, &$form_state) {
  $space = $form_state['values']['space'];
  $preset = spaces_preset_load(variable_get('spaces_preset_' . $space->type, NULL), NULL, TRUE);
  $selected = FALSE;
  $space
    ->activate();
  foreach (array_keys(spaces_controllers()) as $controller) {
    $save = !empty($form_state['values'][$controller]) ? array_filter($form_state['values'][$controller]) : array();
    foreach (array_keys($save) as $key) {
      $override = $space->controllers->{$controller}
        ->get($key, 'space');
      if ($override !== NULL) {
        $selected = TRUE;
        $preset->value[$controller][$key] = $override;
      }
    }
  }
  if ($selected) {
    spaces_preset_save($preset);
    drupal_set_message(t('Saved preset %title.', array(
      '%title' => $preset->title,
    )));
  }
  else {
    drupal_set_message(t('You need to select at least one override to save to the preset.'), 'error');
  }
}