You are here

public function BoundaryFilter::acceptExposedInput in Geolocation Field 8

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

Determines if the input from a filter should change the generated query.

Parameters

array $input: The exposed data for this view.

Return value

bool TRUE if the input for this filter should be included in the view query. FALSE otherwise.

Overrides FilterPluginBase::acceptExposedInput

File

src/Plugin/views/filter/BoundaryFilter.php, line 253

Class

BoundaryFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation\Plugin\views\filter

Code

public function acceptExposedInput($input) {
  $return_value = parent::acceptExposedInput($input);
  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']], $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['boundary'])) {
          $this->value = array_replace($input[$this->options['expose']['identifier']], $location_data['boundary']);
        }
        else {
          $this->value = $input[$this->options['expose']['identifier']];
        }
      }
    }
  }
  return $return_value;
}