You are here

function openlayers_ui_layers_form_submit in Openlayers 6.2

Submit handler for layers.

File

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

Code

function openlayers_ui_layers_form_submit(&$form, &$form_state) {

  // Save preset
  $layer_class = $form_state['values']['data']['layer_type'];
  $layer = openlayers_layer_type_load($layer_class);
  $layer->name = $form_state['values']['name'];
  $layer->title = $form_state['values']['title'];
  $layer->description = $form_state['values']['description'];
  $layer->data = $form_state['values']['data'];
  if (isset($layer->data['resolutions'])) {

    // resolutions are stored as strings because floats are not handled
    // well by formapi
    $layer->data['resolutions'] = array_map("floatval", array_keys($layer->data['resolutions']));
    rsort($layer->data['resolutions']);
  }
  $success = $layer
    ->save();

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