You are here

function openlayers_ui_maps_form_process in Openlayers 7.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_maps_form_process()
openlayers_maps_ui::edit_form in modules/openlayers_ui/plugins/export_ui/openlayers_maps_ui.class.php
Provide the actual editing form.
openlayers_maps_ui::edit_form_submit in modules/openlayers_ui/plugins/export_ui/openlayers_maps_ui.class.php
Prepare the tag values before they are added to the database.

File

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

Code

function openlayers_ui_maps_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_weight',
    'layer_styles',
    'layer_styles_select',
    'layer_styles_temporary',
    '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['layerstyles']['projections']['easy_projection'];
        $processed['displayProjection'] = $values['layerstyles']['projections']['displayProjection'];
        break;
      case 'layers':

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

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

          // TODO: Above code is terrrrrrrrible. rewrite when I have the time
        }

        // Merge our different layer sections together
        $processed['layers'] = array_merge($baselayers, $overlays);
        break;
      case 'layer_weight':
      case 'layer_styles':
      case 'layer_styles_select':
      case 'layer_styles_temporary':
      case 'layer_activated':
      case 'layer_switcher':
      case 'projections':
      case 'styles':
        $processed[$key] = isset($values['layerstyles'][$key]) ? $values['layerstyles'][$key] : array();
        break;
      default:

        // $processed[$key] = is_array($values[$key]) ?
        //   array_filter($values[$key]) : $values[$key];
        $processed[$key] = isset($values[$key]) ? $values[$key] : array();
        break;
    }
  }

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