You are here

public function GeocoderArgument::buildOptionsForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/argument/GeocoderArgument.php \Drupal\geolocation\Plugin\views\argument\GeocoderArgument::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides ProximityArgument::buildOptionsForm

File

src/Plugin/views/argument/GeocoderArgument.php, line 73

Class

GeocoderArgument
Argument handler for geolocation.

Namespace

Drupal\geolocation\Plugin\views\argument

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $geocoder_options = [];
  foreach ($this->geocoderManager
    ->getDefinitions() as $id => $definition) {
    if (empty($definition['frontendCapable'])) {
      continue;
    }
    $geocoder_options[$id] = $definition['name'];
  }
  if ($geocoder_options) {
    $form['geocoder'] = [
      '#type' => 'select',
      '#options' => $geocoder_options,
      '#title' => $this
        ->t('Geocoder plugin'),
      '#default_value' => $this->options['geocoder'],
      '#ajax' => [
        'callback' => [
          get_class($this->geocoderManager),
          'addGeocoderSettingsFormAjax',
        ],
        'wrapper' => 'argument-geocoder-plugin-settings',
        'effect' => 'fade',
      ],
    ];
    if (!empty($this->options['geocoder'])) {
      $geocoder_plugin = $this->geocoderManager
        ->getGeocoder($this->options['geocoder'], $this->options['geocoder_settings'] ?: []);
    }
    elseif (current(array_keys($geocoder_options))) {
      $geocoder_plugin = $this->geocoderManager
        ->getGeocoder(current(array_keys($geocoder_options)));
    }
    if (!empty($geocoder_plugin)) {
      $geocoder_settings_form = $geocoder_plugin
        ->getOptionsForm();
      if ($geocoder_settings_form) {
        $form['geocoder_settings'] = $geocoder_settings_form;
      }
    }
    if (empty($form['geocoder_settings'])) {
      $form['geocoder_settings'] = [
        '#type' => 'html_tag',
        '#tag' => 'span',
        '#value' => $this
          ->t("No settings available."),
      ];
    }
    $form['geocoder_settings'] = array_replace_recursive($form['geocoder_settings'], [
      '#flatten' => TRUE,
      '#prefix' => '<div id="argument-geocoder-plugin-settings">',
      '#suffix' => '</div>',
    ]);
  }
}