You are here

protected function GeofieldMapFieldTrait::preProcessMapSettings in Geofield Map 8.2

Same name and namespace in other branches
  1. 8 src/GeofieldMapFieldTrait.php \Drupal\geofield_map\GeofieldMapFieldTrait::preProcessMapSettings()

Pre Process the MapSettings.

Performs some preprocess on the maps settings before sending to js.

Parameters

array $map_settings: The map settings.

2 calls to GeofieldMapFieldTrait::preProcessMapSettings()
GeofieldGoogleMapFormatter::viewElements in src/Plugin/Field/FieldFormatter/GeofieldGoogleMapFormatter.php
Builds a renderable array for a field value.
GeofieldGoogleMapViewStyle::render in src/Plugin/views/style/GeofieldGoogleMapViewStyle.php
Renders the View.

File

src/GeofieldMapFieldTrait.php, line 294

Class

GeofieldMapFieldTrait
Class GeofieldMapFieldTrait.

Namespace

Drupal\geofield_map

Code

protected function preProcessMapSettings(array &$map_settings) {

  /* @var \Drupal\Core\Config\ConfigFactoryInterface $config */
  $config = $this->config;
  $geofield_map_settings = $config
    ->getEditable('geofield_map.settings');

  // Set the gmap_api_key as map settings.
  $map_settings['gmap_api_key'] = $this
    ->getGmapApiKey();

  // Geofield Map Google Maps and Geocoder Settings.
  $map_settings['gmap_api_localization'] = $this->googleMapsService
    ->getGmapApiLocalization($geofield_map_settings
    ->get('gmap_api_localization'));

  // Transform into simple array values the map_type_control_options_type_ids.
  $map_settings['map_controls']['map_type_control_options_type_ids'] = array_keys(array_filter($map_settings['map_controls']['map_type_control_options_type_ids'], function ($value) {
    return $value !== 0;
  }));

  // Generate Absolute icon_image_path, if it is not.
  $icon_image_path = $map_settings['map_marker_and_infowindow']['icon_image_path'];
  if (!empty($icon_image_path) && !UrlHelper::isExternal($map_settings['map_marker_and_infowindow']['icon_image_path'])) {
    $map_settings['map_marker_and_infowindow']['icon_image_path'] = Url::fromUri('base:', [
      'absolute' => TRUE,
    ])
      ->toString() . $icon_image_path;
  }
}