You are here

function openlayers_ui_presets_form_process in Openlayers 6.2

Process form submission into a map array.

Parameters

$values: Array of values to process.

Return value

Map data array.

2 calls to openlayers_ui_presets_form_process()
openlayers_ui_presets_form_submit in modules/openlayers_ui/includes/openlayers_ui.presets.inc
Form submit for preset add form
openlayers_ui_presets_form_validate in modules/openlayers_ui/includes/openlayers_ui.presets.inc
OpenLayers Preset Form Validate

File

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

Code

function openlayers_ui_presets_form_process($values = array()) {

  // Valid keys that we will cherry-pick from the form values.
  $keys = array(
    'width',
    'height',
    'image_path',
    'css_path',
    'proxy_host',
    'hide_empty_map',
    'center',
    'behaviors',
    'layers',
    'layer_styles',
    'layer_activated',
    'layer_switcher',
    'projections',
    'styles',
  );

  // TODO: eliminate this process, too much disconnect between
  // forms and data
  $processed = array();
  foreach ($keys as $key) {
    switch ($key) {
      case 'behaviors':
        $processed['behaviors'] = array();
        foreach ($values['behaviors'] as $behavior => $settings) {
          if ($settings['enabled']) {
            $processed['behaviors'][$behavior] = isset($settings['options_set']['options']) ? $settings['options_set']['options'] : array();
          }
        }
        break;
      case 'projections':
        $processed['projection'] = $values['projections']['easy_projection'];
        $processed['displayProjection'] = $values['projections']['displayProjection'];
        break;
      case 'layers':

        // Put the default layer in the right place.
        // TODO: finish port here
        $processed['default_layer'] = $values['layers']['default_layer'];
        $baselayers = array_filter($values['layers']['baselayers']);

        // Sort overlay layers by weight, in case browser didn't
        // send them already sorted
        $overlays = array();
        if (!empty($values['layers']['overlays'])) {
          asort($values['layer_weight']);
          foreach (array_keys($values['layer_weight']) as $key) {
            if ($values['layers']['overlays'][$key]) {
              $overlays[$key] = $key;
            }
          }
        }

        // Merge our different layer sections together
        $processed['layers'] = array_merge($baselayers, $overlays);
        break;
      case 'layer_styles':
        $processed['layer_styles'] = array();
        if (!empty($values['layer_styles'])) {
          foreach ($values['layer_styles'] as $layer => $stylespec) {
            $layerarray = array_filter($stylespec);
            if (!empty($layerarray)) {
              $processed['layer_styles'][$layer] = $layerarray;
            }
          }
        }
        break;
      default:
        $processed[$key] = is_array($values[$key]) ? array_filter($values[$key]) : $values[$key];
        break;
    }
  }

  // Ensure these values are arrays
  $ensure_array = array(
    'behaviors',
    'layers',
    'layer_styles',
    'styles',
  );
  foreach ($ensure_array as $key) {
    if (empty($processed[$key])) {
      $processed[$key] = array();
    }
  }
  return $processed;
}