You are here

public function LeafletService::setGeocoderControlSettings in Leaflet 2.1.x

Same name and namespace in other branches
  1. 8 src/LeafletService.php \Drupal\leaflet\LeafletService::setGeocoderControlSettings()
  2. 2.0.x src/LeafletService.php \Drupal\leaflet\LeafletService::setGeocoderControlSettings()

Set Geocoder Controls Settings.

Parameters

array $geocoder_settings: The geocoder settings.

array $attached_libraries: The attached libraries.

1 call to LeafletService::setGeocoderControlSettings()
LeafletService::leafletRenderMap in src/LeafletService.php
Load all Leaflet required client files and return markup for a map.

File

src/LeafletService.php, line 407

Class

LeafletService
Provides a LeafletService class.

Namespace

Drupal\leaflet

Code

public function setGeocoderControlSettings(array &$geocoder_settings, array &$attached_libraries) : void {
  if ($this->moduleHandler
    ->moduleExists('geocoder') && class_exists('\\Drupal\\geocoder\\Controller\\GeocoderApiEnpoints') && $geocoder_settings['control'] && $this->currentUser
    ->hasPermission('access geocoder api endpoints')) {
    $attached_libraries[] = 'leaflet/leaflet.geocoder';

    // Set the geocoder settings ['providers'] as the enabled ones.
    $enabled_providers = [];
    foreach ($geocoder_settings['settings']['providers'] as $plugin_id => $plugin) {
      if (!empty($plugin['checked'])) {
        $enabled_providers[] = $plugin_id;
      }
    }
    $geocoder_settings['settings']['providers'] = $enabled_providers;
    $geocoder_settings['settings']['options'] = [
      'options' => Json::decode($geocoder_settings['settings']['options']) ?? '',
    ];
  }
}