You are here

public function GeofieldProximitySort::buildOptionsForm in Geofield 8

Basic options for all sort criteria

Overrides SortPluginBase::buildOptionsForm

File

src/Plugin/views/sort/GeofieldProximitySort.php, line 90

Class

GeofieldProximitySort
Field handler to sort Geofields by proximity.

Namespace

Drupal\geofield\Plugin\views\sort

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);
  $form['units']['#default_value'] = $this->options['units'];
  $form['source']['#default_value'] = $this->options['source'];
  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);
}