You are here

public function SearchApiLocationRadius::query in Search API Location 8

Set up the query for this argument.

The argument sent may be found at $this->argument.

Overrides ArgumentPluginBase::query

File

modules/search_api_location_views/src/Plugin/views/argument/SearchApiLocationRadius.php, line 23

Class

SearchApiLocationRadius
Provides a contextual filter for defining a location filter radius.

Namespace

Drupal\search_api_location_views\Plugin\views\argument

Code

public function query($group_by = FALSE) {

  // Must be single and must be a decimal.
  if (is_numeric($this->argument) && $this->argument > 0) {
    $query = $this
      ->getQuery();
    $location_options = (array) $query
      ->getOption('search_api_location');
    $add_options = [
      'radius' => $this->argument,
    ];

    // We currently have no way of knowing what part of the field name was
    // added to have the distance pseudo field name.
    // So for now we remove '__distance' from the field name to get the
    // location field.

    /* @see search_api_location_views_views_data_alter */
    $location_field_name = str_replace('__distance', '', $this->realField);
    $this
      ->addFieldOptions($location_options, $add_options, $location_field_name);
    $query
      ->setOption('search_api_location', $location_options);
  }
}