public function MapProviderBase::getSettingsForm in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 src/MapProviderBase.php \Drupal\geolocation\MapProviderBase::getSettingsForm()
Provide a generic map settings form array.
Parameters
array $settings: The current map settings.
array $parents: Form parents.
Return value
array A form array to be integrated in whatever.
Overrides MapProviderInterface::getSettingsForm
4 calls to MapProviderBase::getSettingsForm()
- GoogleMapsProviderBase::getSettingsForm in modules/
geolocation_google_maps/ src/ GoogleMapsProviderBase.php - Provide a generic map settings form array.
- Here::getSettingsForm in modules/
geolocation_here/ src/ Plugin/ geolocation/ MapProvider/ Here.php - Provide a generic map settings form array.
- Leaflet::getSettingsForm in modules/
geolocation_leaflet/ src/ Plugin/ geolocation/ MapProvider/ Leaflet.php - Provide a generic map settings form array.
- Yandex::getSettingsForm in modules/
geolocation_yandex/ src/ Plugin/ geolocation/ MapProvider/ Yandex.php - Provide a generic map settings form array.
4 methods override MapProviderBase::getSettingsForm()
- GoogleMapsProviderBase::getSettingsForm in modules/
geolocation_google_maps/ src/ GoogleMapsProviderBase.php - Provide a generic map settings form array.
- Here::getSettingsForm in modules/
geolocation_here/ src/ Plugin/ geolocation/ MapProvider/ Here.php - Provide a generic map settings form array.
- Leaflet::getSettingsForm in modules/
geolocation_leaflet/ src/ Plugin/ geolocation/ MapProvider/ Leaflet.php - Provide a generic map settings form array.
- Yandex::getSettingsForm in modules/
geolocation_yandex/ src/ Plugin/ geolocation/ MapProvider/ Yandex.php - Provide a generic map settings form array.
File
- src/
MapProviderBase.php, line 129
Class
- MapProviderBase
- Class MapProviderBase.
Namespace
Drupal\geolocationCode
public function getSettingsForm(array $settings, array $parents = []) {
$form = [
'#type' => 'details',
'#title' => $this
->t('%map_provider settings', [
'%map_provider' => $this->pluginDefinition['name'],
]),
'#description' => $this
->t('Additional map settings provided by %map_provider', [
'%map_provider' => $this->pluginDefinition['name'],
]),
];
$map_features = $this->mapFeatureManager
->getMapFeaturesByMapType($this
->getPluginId());
if (empty($map_features)) {
return $form;
}
$form['map_features'] = [
'#type' => 'table',
'#weight' => 100,
'#prefix' => $this
->t('<h3>Map Features</h3>'),
'#header' => [
$this
->t('Enable'),
$this
->t('Feature'),
$this
->t('Settings'),
$this
->t('Weight'),
],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'geolocation-map-feature-option-weight',
],
],
];
$form['map_features']['#element_validate'][] = [
$this,
'validateMapFeatureForms',
];
foreach ($map_features as $feature_id => $feature_definition) {
$feature = $this->mapFeatureManager
->getMapFeature($feature_id, []);
if (empty($feature)) {
continue;
}
$feature_enable_id = Html::getUniqueId($feature_id . '_enabled');
$weight = isset($settings['map_features'][$feature_id]['weight']) ? $settings['map_features'][$feature_id]['weight'] : 0;
$form['map_features'][$feature_id] = [
'#weight' => $weight,
'#attributes' => [
'class' => [
'draggable',
],
],
'enabled' => [
'#attributes' => [
'id' => $feature_enable_id,
],
'#type' => 'checkbox',
'#default_value' => empty($settings['map_features'][$feature_id]['enabled']) ? FALSE : TRUE,
],
'feature' => [
'#type' => 'label',
'#title' => $feature_definition['name'],
'#suffix' => $feature_definition['description'],
],
'weight' => [
'#type' => 'weight',
'#title' => $this
->t('Weight for @option', [
'@option' => $feature_definition['name'],
]),
'#title_display' => 'invisible',
'#size' => 4,
'#default_value' => $weight,
'#attributes' => [
'class' => [
'geolocation-map-feature-option-weight',
],
],
],
];
$feature_form = $feature
->getSettingsForm(empty($settings['map_features'][$feature_id]['settings']) ? [] : $settings['map_features'][$feature_id]['settings'], array_merge($parents, [
'map_features',
$feature_id,
'settings',
]));
if (!empty($feature_form)) {
$feature_form['#states'] = [
'visible' => [
':input[id="' . $feature_enable_id . '"]' => [
'checked' => TRUE,
],
],
];
$feature_form['#type'] = 'item';
$form['map_features'][$feature_id]['settings'] = $feature_form;
}
}
uasort($form['map_features'], [
SortArray::class,
'sortByWeightProperty',
]);
return $form;
}