public function MarkerIcon::alterMap in Geolocation Field 8.3
Same name and namespace in other branches
- 8.2 modules/geolocation_google_maps/src/Plugin/geolocation/MapFeature/MarkerIcon.php \Drupal\geolocation_google_maps\Plugin\geolocation\MapFeature\MarkerIcon::alterMap()
Alter render array.
Parameters
array $render_array: Render array.
array $feature_settings: The current feature settings.
array $context: Context like field formatter, field widget or view.
Return value
array Render array.
Overrides MapFeatureBase::alterMap
File
- modules/
geolocation_google_maps/ src/ Plugin/ geolocation/ MapFeature/ MarkerIcon.php, line 141
Class
- MarkerIcon
- Provides Google Maps.
Namespace
Drupal\geolocation_google_maps\Plugin\geolocation\MapFeatureCode
public function alterMap(array $render_array, array $feature_settings, array $context = []) {
$render_array = parent::alterMap($render_array, $feature_settings, $context);
$render_array['#attached'] = BubbleableMetadata::mergeAttachments(empty($render_array['#attached']) ? [] : $render_array['#attached'], [
'library' => [
'geolocation_google_maps/mapfeature.' . $this
->getPluginId(),
],
'drupalSettings' => [
'geolocation' => [
'maps' => [
$render_array['#id'] => [
$this
->getPluginId() => [
'enable' => TRUE,
'anchor' => $feature_settings['anchor'],
'size' => $feature_settings['size'],
'scaledSize' => $feature_settings['scaled_size'],
'labelOrigin' => $feature_settings['label_origin'],
'origin' => $feature_settings['origin'],
],
],
],
],
],
]);
if (!empty($feature_settings['marker_icon_path'])) {
$path = \Drupal::token()
->replace($feature_settings['marker_icon_path'], $context);
$path = file_create_url($path);
$render_array['#attached']['drupalSettings']['geolocation']['maps'][$render_array['#id']][$this
->getPluginId()]['markerIconPath'] = $path;
if (!empty($render_array['#children']['locations'])) {
foreach ($render_array['#children']['locations'] as &$location) {
if (empty($location['#icon'])) {
$location['#icon'] = $path;
}
}
}
}
return $render_array;
}