You are here

public function ProximityFilter::acceptExposedInput in Geolocation Field 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/views/filter/ProximityFilter.php \Drupal\geolocation\Plugin\views\filter\ProximityFilter::acceptExposedInput()
  2. 8.2 src/Plugin/views/filter/ProximityFilter.php \Drupal\geolocation\Plugin\views\filter\ProximityFilter::acceptExposedInput()

Do some minor translation of the exposed input

Overrides NumericFilter::acceptExposedInput

File

src/Plugin/views/filter/ProximityFilter.php, line 304

Class

ProximityFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation\Plugin\views\filter

Code

public function acceptExposedInput($input) {
  $value = parent::acceptExposedInput($input);
  if (empty($value)) {
    return FALSE;
  }
  if ($this->options['proximity_source'] == 'exposed') {
    if ($this->options['expose']['input_by_geocoding_widget'] && !empty($this->options['expose']['geocoder_plugin_settings']['plugin_id'])) {
      $geocoder_configuration = $this->options['expose']['geocoder_plugin_settings']['settings'];

      /** @var \Drupal\geolocation\GeocoderInterface $geocoder_plugin */
      $geocoder_plugin = $this->geolocationCore
        ->getGeocoderManager()
        ->getGeocoder($this->options['expose']['geocoder_plugin_settings']['plugin_id'], $geocoder_configuration);
      if (!empty($geocoder_plugin)) {
        $location_data = $geocoder_plugin
          ->formProcessInput($input, $this->options['expose']['identifier']);

        // No location found at all.
        if (!$location_data) {
          $this->value = [];

          // Accept it anyway, to ensure empty result.
          return TRUE;
        }
        else {

          // Location geocoded server-side. Add to input for later processing.
          if (!empty($location_data['location'])) {
            $this->value[$this->options['expose']['identifier'] . '-lat'] = $location_data['location']['lat'];
            $this->value[$this->options['expose']['identifier'] . '-lng'] = $location_data['location']['lng'];
          }
          else {
            $this->value[$this->options['expose']['identifier'] . '-lat'] = $input[$this->options['expose']['identifier'] . '-lat'];
            $this->value[$this->options['expose']['identifier'] . '-lng'] = $input[$this->options['expose']['identifier'] . '-lng'];
          }
        }
      }
    }
    elseif (!$this
      ->isAGroup()) {

      // Proximity source set to "expose ins & retrieve from exposed form".
      $this->value[$this->options['expose']['identifier'] . '-lat'] = $input[$this->options['expose']['identifier'] . '-lat'];
      $this->value[$this->options['expose']['identifier'] . '-lng'] = $input[$this->options['expose']['identifier'] . '-lng'];
    }
  }
  if ($this->options['proximity_units'] == 'exposed') {
    if ($input[$this->options['expose']['identifier'] . '-units'] != 'km' && $input[$this->options['expose']['identifier'] . '-units'] != 'mile') {
      return FALSE;
    }
    else {
      $this->value['units'] = $input[$this->options['expose']['identifier'] . '-units'];
    }
  }
  return $value;
}