You are here

function openlayers_ui_import_validate in Openlayers 6.2

Validate handler to import a preset

1 string reference to 'openlayers_ui_import_validate'
openlayers_ui_import_page in modules/openlayers_ui/openlayers_ui.module
Import a preset from cut & paste

File

modules/openlayers_ui/openlayers_ui.module, line 582

Code

function openlayers_ui_import_validate($form, &$form_state) {
  $view = '';
  ob_start();
  eval($form_state['values']['preset']);
  ob_end_clean();
  if (!is_object($preset)) {
    return form_error($form['view'], t('Unable to interpret preset 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('Preset name must be alphanumeric or underscores only.'));
  }
  if ($form_state['values']['name']) {
    $preset->name = $form_state['values']['name'];
  }
  $test = openlayers_preset_load($preset->name);
  if ($test && $test->type != t('Default')) {
    form_set_error('', t('A preset by that name already exists; please choose a different name'));
  }

  // TODO: The import process should test layer existence
  $form_state['preset'] =& $preset;
}