public function LeafletControlGeocoder::getSettingsForm in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletControlGeocoder.php \Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature\LeafletControlGeocoder::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_leaflet/ src/ Plugin/ geolocation/ MapFeature/ LeafletControlGeocoder.php, line 73
Class
- LeafletControlGeocoder
- Provides Geocoder control element.
Namespace
Drupal\geolocation_leaflet\Plugin\geolocation\MapFeatureCode
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' => '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="geocoder-plugin-settings">',
'#suffix' => '</div>',
]);
}
return $form;
}