public function LeafletControlLayer::getSettingsForm in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletControlLayer.php \Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature\LeafletControlLayer::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/ LeafletControlLayer.php, line 35
Class
- LeafletControlLayer
- Provides Tile Layer control element.
Namespace
Drupal\geolocation_leaflet\Plugin\geolocation\MapFeatureCode
public function getSettingsForm(array $settings, array $parents) {
$form = parent::getSettingsForm($settings, $parents);
if ($parents) {
$first = array_shift($parents);
$parents_string = $first . '[' . implode('][', $parents);
}
else {
$parents_string = NULL;
}
$settings = $this
->getSettings($settings);
$form['default_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default layer label'),
'#description' => $this
->t('Label for the layer in the control.'),
'#default_value' => $settings['default_label'],
];
$form['tile_layer_providers'] = [
'#type' => 'details',
'#title' => $this
->t('Providers'),
];
$providers = $this
->getBaseMaps();
$form['tile_providers_options'] = $this
->getProviderOptionsForm($settings['tile_providers_options']);
foreach ($providers as $provider => $variants) {
$form['tile_layer_providers'][$provider] = [
'#type' => 'details',
'#title' => $provider,
];
foreach ($variants as $key => $variant) {
$form['tile_layer_providers'][$provider][$key]['checkbox'] = [
'#type' => 'checkbox',
'#title' => $variant,
'#default_value' => isset($settings['tile_layer_providers'][$provider][$key]['checkbox']) ? $settings['tile_layer_providers'][$provider][$key]['checkbox'] : 0,
];
$form['tile_layer_providers'][$provider][$key]['label'] = [
'#type' => 'textfield',
'#description' => $this
->t('Label for the layer in the control.'),
'#default_value' => isset($settings['tile_layer_providers'][$provider][$key]['label']) ? $settings['tile_layer_providers'][$provider][$key]['label'] : '',
'#states' => [
'visible' => [
':input[name="' . $parents_string . '][tile_layer_providers][' . $provider . '][' . $key . '][checkbox]"]' => [
'checked' => TRUE,
],
],
],
];
}
if (in_array($provider, $this->register)) {
$states = [];
foreach ($providers[$provider] as $key => $variant) {
$states[][':input[name="' . $parents_string . '][tile_layer_providers][' . $provider . '][' . $key . '][checkbox]"]'] = [
'checked' => TRUE,
];
}
foreach ($form['tile_providers_options'][$provider] as $key => $value) {
$form['tile_providers_options'][$provider][$key]['#states']['visible'] = $states;
}
}
}
return $form;
}