You are here

function openlayers_ui_presets_form_submit in Openlayers 6.2

Form submit for preset add form

File

modules/openlayers_ui/includes/openlayers_ui.presets.inc, line 500
This file holds the functions handling presets in the Openlayers UI.

Code

function openlayers_ui_presets_form_submit($form, &$form_state) {

  // Check for cancel
  if ($form_state['clicked_button']['#id'] == 'edit-openlayers-cancel') {
    $form_state['redirect'] = 'admin/build/openlayers/presets/list';
  }

  // Only save if save button is pressed
  if ($form_state['clicked_button']['#id'] == 'edit-openlayers-save') {
    $map = openlayers_ui_presets_form_process($form_state['values']);

    // Save preset
    $preset = new stdClass();
    $preset->name = $form_state['values']['name'];
    $preset->title = $form_state['values']['title'];
    $preset->description = $form_state['values']['description'];
    $preset->data = $map;
    $success = openlayers_preset_save($preset);

    // Redirect to edit page
    if ($success) {
      drupal_set_message(t('Map saved.'));
      $form_state['redirect'] = "admin/build/openlayers/presets/{$preset->name}/edit";
    }
    else {
      form_set_error('openlayers', t('Error trying to save map'));
    }
  }
}