You are here

public function BoundaryFilter::buildExposedForm 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::buildExposedForm()
  2. 8.2 src/Plugin/views/filter/BoundaryFilter.php \Drupal\geolocation\Plugin\views\filter\BoundaryFilter::buildExposedForm()

Render our chunk of the exposed filter form when selecting

You can override this if it doesn't do what you expect.

Overrides FilterPluginBase::buildExposedForm

File

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

Class

BoundaryFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation\Plugin\views\filter

Code

public function buildExposedForm(&$form, FormStateInterface $form_state) {
  parent::buildExposedForm($form, $form_state);
  $identifier = $this->options['expose']['identifier'];
  if ($this->options['expose']['input_by_geocoding_widget'] && !empty($form[$identifier]) && !empty($this->options['expose']['geocoder_plugin_settings'])) {
    $geocoder_configuration = $this->options['expose']['geocoder_plugin_settings']['settings'];
    $geocoder_configuration['label'] = $this->options['expose']['label'];

    /** @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)) {
      return;
    }
    $form[$identifier]['lat_north_east']['#type'] = 'hidden';
    $form[$identifier]['lng_north_east']['#type'] = 'hidden';
    $form[$identifier]['lat_south_west']['#type'] = 'hidden';
    $form[$identifier]['lng_south_west']['#type'] = 'hidden';
    $geocoder_plugin
      ->formAttachGeocoder($form[$this->options['expose']['identifier']], $identifier);
    $form = array_merge_recursive($form, [
      '#attached' => [
        'library' => [
          'geolocation/geolocation.views.filter.geocoder',
        ],
        'drupalSettings' => [
          'geolocation' => [
            'geocoder' => [
              'viewsFilterGeocoder' => [
                $identifier => [
                  'type' => 'boundary',
                ],
              ],
            ],
          ],
        ],
      ],
    ]);
  }
}