You are here

public function Field::optionsFormSubmit in Openlayers 7.3

Submit callback for the options form.

Parameters

array $form: The form array.

array $form_state: The form_state array by reference.

Overrides Base::optionsFormSubmit

File

modules/openlayers_field/src/Plugin/Source/Field/Field.php, line 97
Source: Field.

Class

Field
Class Field.

Namespace

Drupal\openlayers_field\Plugin\Source\Field

Code

public function optionsFormSubmit(array $form, array &$form_state) {
  $fields = $form_state['values']['options']['fields'];
  $geocoder_handler = $form_state['values']['options']['geocoder_handler'];
  $geocoder_cache = $form_state['values']['options']['geocoder_cache'];

  // This is for optimizing the source rendering in JS.
  // It converts all the address fields of the source to WKT.
  foreach ($fields as $index => &$field) {
    if (isset($field['address']) && !empty($field['address'])) {
      $geocoder = geocoder($geocoder_handler, $field['address'], array(), $geocoder_cache);
      if (!is_null($geocoder)) {
        $field['wkt'] = $geocoder
          ->out('wkt');
      }
      else {
        unset($field['geojson']);
      }
    }
    else {
      unset($fields[$index]);
    }
  }
  $form_state['values']['options']['fields'] = $fields;
  parent::optionsFormSubmit($form, $form_state);
}