You are here

public function LeafletTileLayer::getSettingsForm in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletTileLayer.php \Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature\LeafletTileLayer::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 MapFeatureBase::getSettingsForm

File

modules/geolocation_leaflet/src/Plugin/geolocation/MapFeature/LeafletTileLayer.php, line 35

Class

LeafletTileLayer
Provides map tile layer support.

Namespace

Drupal\geolocation_leaflet\Plugin\geolocation\MapFeature

Code

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;
  }
  $providers = $this
    ->getBaseMaps();
  $form['tile_layer_provider'] = [
    '#type' => 'select',
    '#options' => $providers,
    '#default_value' => $settings['tile_layer_provider'],
  ];
  $form['tile_provider_options'] = $this
    ->getProviderOptionsForm($settings['tile_provider_options']);
  foreach ($this->register as $provider) {
    $states = [];
    foreach ($providers[$provider] as $key => $variant) {
      $states[][':input[name="' . $parents_string . '][tile_layer_provider]"]'] = [
        'value' => $key,
      ];
    }
    foreach ($form['tile_provider_options'][$provider] as $key => $value) {
      $form['tile_provider_options'][$provider][$key]['#states']['visible'] = $states;
    }
  }
  return $form;
}