You are here

public function Geocoder::getSettingsForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/geolocation/LocationInput/Geocoder.php \Drupal\geolocation\Plugin\geolocation\LocationInput\Geocoder::getSettingsForm()

Settings form by ID and context.

Parameters

int $center_option_id: LocationInput option ID.

array $settings: The current option settings.

mixed $context: Current context.

Return value

array A form array to be integrated in whatever.

Overrides LocationInputBase::getSettingsForm

File

src/Plugin/geolocation/LocationInput/Geocoder.php, line 76

Class

Geocoder
Location based proximity center.

Namespace

Drupal\geolocation\Plugin\geolocation\LocationInput

Code

public function getSettingsForm($option_id = NULL, array $settings = [], $context = NULL) {
  $form = [];
  $settings = $this
    ->getSettings($settings);
  $geocoder_options = [];
  foreach ($this->geocoderManager
    ->getDefinitions() as $geocoder_id => $geocoder_definition) {
    if (empty($geocoder_definition['locationCapable'])) {
      continue;
    }
    $geocoder_options[$geocoder_id] = $geocoder_definition['name'];
  }
  if ($geocoder_options) {
    $form['plugin_id'] = [
      '#type' => 'select',
      '#options' => $geocoder_options,
      '#title' => $this
        ->t('Geocoder plugin'),
      '#default_value' => $settings['plugin_id'],
      '#ajax' => [
        'callback' => [
          get_class($this->geocoderManager),
          'addGeocoderSettingsFormAjax',
        ],
        'wrapper' => 'location-input-geocoder-plugin-settings',
        'effect' => 'fade',
      ],
    ];
    if (!empty($settings['plugin_id'])) {
      $geocoder_plugin = $this->geocoderManager
        ->getGeocoder($settings['plugin_id'], $settings['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['settings'] = $geocoder_settings_form;
      }
    }
    if (empty($form['settings'])) {
      $form['settings'] = [
        '#type' => 'html_tag',
        '#tag' => 'span',
        '#value' => $this
          ->t("No settings available."),
      ];
    }
    $form['settings'] = array_replace_recursive($form['settings'], [
      '#flatten' => TRUE,
      '#prefix' => '<div id="location-input-geocoder-plugin-settings">',
      '#suffix' => '</div>',
    ]);
    $form['auto_submit'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Auto-submit form'),
      '#default_value' => $settings['auto_submit'],
      '#description' => $this
        ->t('Only triggers if location could be set'),
    ];
    $form['hide_form'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Hide coordinates form'),
      '#default_value' => $settings['hide_form'],
    ];
  }
  return $form;
}