You are here

public function ProximityFilter::valueForm in Geolocation Field 8.3

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

Provide a simple textfield for equality

Overrides NumericFilter::valueForm

File

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

Class

ProximityFilter
Filter handler for search keywords.

Namespace

Drupal\geolocation\Plugin\views\filter

Code

public function valueForm(&$form, FormStateInterface $form_state) {
  parent::valueForm($form, $form_state);
  $form['#tree'] = TRUE;
  if (!isset($form['value']['value'])) {
    $form['value'] = array_replace($form['value'], [
      '#type' => 'number',
      '#min' => 0,
      '#step' => 0.1,
      '#title' => $this
        ->t('Distance'),
      '#description' => $this
        ->t('Distance in %unit', [
        '%unit' => $this->options['unit'] === 'km' ? $this
          ->t('Kilometers') : $this
          ->t('Miles'),
      ]),
      '#default_value' => $form['value']['#default_value'],
    ]);
  }
  else {
    $form['value']['value'] = array_replace($form['value']['value'], [
      '#type' => 'number',
      '#min' => 0,
      '#step' => 0.1,
      '#title' => $this
        ->t('Distance'),
      '#description' => $this
        ->t('Distance in %unit', [
        '%unit' => $this->options['unit'] === 'km' ? $this
          ->t('Kilometers') : $this
          ->t('Miles'),
      ]),
      '#default_value' => $form['value']['value']['#default_value'],
    ]);
  }
  $form['center'] = $this->locationInputManager
    ->getForm($this->options['location_input'], $this, empty($this->value['center']) ? NULL : $this->value['center']);
}