You are here

public function GeofieldProximityFilter::buildOptionsForm in Geofield 8

Provide the basic form which calls through to subforms. If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called.

Overrides FilterPluginBase::buildOptionsForm

File

src/Plugin/views/filter/GeofieldProximityFilter.php, line 254

Class

GeofieldProximityFilter
Field handler to filter Geofields by proximity.

Namespace

Drupal\geofield\Plugin\views\filter

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  $context = $this->pluginDefinition['plugin_type'];
  $user_input = $form_state
    ->getUserInput();
  $source_plugin_id = isset($user_input['options']['source']) ? $user_input['options']['source'] : $this->options['source'];
  $source_plugin_configuration = isset($user_input['options']['source_configuration']) ? $user_input['options']['source_configuration'] : $this->options['source_configuration'];
  $this->proximitySourceManager
    ->buildCommonFormElements($form, $form_state, $context, $this->options['exposed']);
  $form['units']['#default_value'] = isset($user_input['options']['units']) ? $user_input['options']['units'] : $this->options['units'];
  $form['source']['#default_value'] = $source_plugin_id;
  $form['source_configuration']['exposed_summary'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Expose Summary Description for the specific Proximity Filter Source'),
    '#default_value' => isset($user_input['options']['source_configuration']['exposed_summary']) ? $user_input['options']['source_configuration']['exposed_summary'] : $this->options['source_configuration']['exposed_summary'],
    '#states' => [
      'visible' => [
        ':input[name="options[expose_button][checkbox][checkbox]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  try {
    $this->sourcePlugin = $this->proximitySourceManager
      ->createInstance($source_plugin_id, $source_plugin_configuration);
    $this->sourcePlugin
      ->setViewHandler($this);
    $form['source_configuration']['origin_description'] = [
      '#markup' => $this->sourcePlugin
        ->getPluginDefinition()['description'],
      '#weight' => -10,
    ];
    $this->sourcePlugin
      ->buildOptionsForm($form['source_configuration'], $form_state, [
      'source_configuration',
    ]);
  } catch (\Exception $e) {
    watchdog_exception('geofield', $e);
  }
  parent::buildOptionsForm($form, $form_state);
}