-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathOpenYMap.php
More file actions
72 lines (64 loc) · 2.39 KB
/
Copy pathOpenYMap.php
File metadata and controls
72 lines (64 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Drupal\openy_map\Element;
use Drupal\Core\Render\Element\RenderElement;
/**
* Class OpenYMap.
*
* @RenderElement("openy_map")
*/
class OpenYMap extends RenderElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return [
'#theme' => 'openy_map',
'#show_controls' => FALSE,
'#pre_render' => [
[$class, 'processElement'],
],
];
}
/**
* Prepare render array for template.
*
* @param array $element
* Element.
*
* @return array
* Element
*/
public static function processElement(array $element) {
$settings = \Drupal::configFactory()->get('openy_map.settings');
$element['#attached']['library'][] = 'openy_map/openy_map';
switch ($settings->get('map_engine')) {
case 'gmaps':
$element['#attached']['library'][] = 'openy_map/gmaps';
$element['#attached']['drupalSettings']['openyMapSettings']['engine'] = 'gmaps';
break;
case 'leaflet':
default:
$element['#attached']['library'][] = 'openy_map/leaflet';
$mapSettings = &$element['#attached']['drupalSettings']['openyMapSettings'];
$mapSettings['engine'] = 'leaflet';
$mapSettings['default_location'] = urlencode(trim(_openy_map_get_default_location()));
$mapSettings['search_icon'] = $settings->get('leaflet.search_icon');
$mapSettings['search_icon_retina'] = $settings->get('leaflet.search_icon_retina');
$mapSettings['base_layer'] = $settings->get('leaflet.base_layer');
$mapSettings['base_layer_override'] = $settings->get('leaflet.base_layer_override');
$element['#attached']['drupalSettings']['openyMapSettings']['leaflet_clustering'] = $settings->get('leaflet.clustering');
$element['#attached']['library'][] = 'openy_map/leaflet.markercluster';
break;
}
$element['#attached']['drupalSettings']['openyMap'] = $element['#element_variables'];
$noscript = $settings->get('noscript_text');
if (!empty($noscript['value'])) {
$element['#noscript_text'] = check_markup($noscript['value'], $noscript['format'] ?? 'plain_text');
}
$tags = $settings->get('default_tags');
$element['#attached']['drupalSettings']['openyMapSettings']['default_tags'] = array_values(array_filter($tags));
$element['#cache']['tags'][] = 'config:openy_map.settings';
return $element;
}
}