You are here

public function ControlCustomGeocoder::getSettingsForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ControlCustomGeocoder.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\ControlCustomGeocoder::getSettingsForm()

Provide a generic map settings form array.

Parameters

array $settings: The current map settings.

array $parents: Form specific optional prefix.

Return value

array A form array to be integrated in whatever.

Overrides ControlElementBase::getSettingsForm

File

modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/ControlCustomGeocoder.php, line 74

Class

ControlCustomGeocoder
Provides Geocoding control element.

Namespace

Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature

Code

public function getSettingsForm(array $settings, array $parents) {
  $form = parent::getSettingsForm($settings, $parents);
  $settings = array_replace_recursive(self::getDefaultSettings(), $settings);
  $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' => $settings['geocoder'],
      '#ajax' => [
        'callback' => [
          get_class($this->geocoderManager),
          'addGeocoderSettingsFormAjax',
        ],
        'wrapper' => 'google-control-geocoder-plugin-settings',
        'effect' => 'fade',
      ],
    ];
    if (!empty($settings['geocoder'])) {
      $geocoder_plugin = $this->geocoderManager
        ->getGeocoder($settings['geocoder'], $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="google-control-geocoder-plugin-settings">',
      '#suffix' => '</div>',
    ]);
  }
  return $form;
}