You are here

function openlayers_ui_layers_import_validate in Openlayers 6.2

Validate handler to import a preset

1 string reference to 'openlayers_ui_layers_import_validate'
openlayers_ui_layers_import_form in modules/openlayers_ui/includes/openlayers_ui.layers.inc
Import a preset from cut & paste

File

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

Code

function openlayers_ui_layers_import_validate($form, &$form_state) {
  $items = '';
  ob_start();
  eval($form_state['values']['layer']);
  ob_end_clean();
  if (!is_array($items)) {
    return form_error($form['layer'], t('Unable to interpret layer code.'));
  }

  // View name must be alphanumeric or underscores, no other punctuation.
  if (!empty($form_state['values']['name']) && preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) {
    form_error($form['name'], t('Layer name must be alphanumeric or underscores only.'));
  }
  $layer = current($items);
  $layer_type_object = openlayers_layer_type_load($layer->data['layer_type']);
  if ($form_state['values']['name']) {
    $layer->name = $form_state['values']['name'];
  }
  if ($exists = openlayers_layer_load($layer->name)) {
    drupal_set_message(t('An existing layer of this name already exists'), 'error');
    $form_state['redirect'] = 'admin/build/openlayers/layers';
  }
  else {
    drupal_set_title(t('Add Layer'));
    $layer_object = new $layer->data['layer_type']($layer);
    $output = drupal_get_form('openlayers_ui_layers_form', $layer_object);
    print theme('page', $output);
    exit;
  }
}