public function GeolocationMapLocation::preRenderLocation in Geolocation Field 8.2
Same name and namespace in other branches
- 8.3 src/Element/GeolocationMapLocation.php \Drupal\geolocation\Element\GeolocationMapLocation::preRenderLocation()
Map element.
Parameters
array $render_array: Element.
Return value
array Renderable map.
File
- src/
Element/ GeolocationMapLocation.php, line 65
Class
- GeolocationMapLocation
- Provides a render element for a single geolocation map location.
Namespace
Drupal\geolocation\ElementCode
public function preRenderLocation(array $render_array) {
$render_array['#theme'] = 'geolocation_map_location';
if (empty($render_array['#id'])) {
$id = uniqid();
$render_array['#id'] = $id;
}
foreach (Element::children($render_array) as $child) {
$render_array['#children'][] = $render_array[$child];
}
if (empty($render_array['#attributes'])) {
$render_array['#attributes'] = [];
}
$render_array['#attributes'] = new Attribute($render_array['#attributes']);
$render_array['#attributes']
->addClass('geolocation-location');
$render_array['#attributes']
->addClass('js-hide');
if (!empty($render_array['#id'])) {
$render_array['#attributes']
->setAttribute('id', $render_array['#id']);
}
$render_array['#attributes']
->setAttribute('data-lat', $render_array['#position']['lat']);
$render_array['#attributes']
->setAttribute('data-lng', $render_array['#position']['lng']);
if (empty($render_array['#hidden'])) {
$render_array['#attributes']
->setAttribute('data-set-marker', 'true');
if (!empty($render_array['#icon'])) {
$render_array['#attributes']
->setAttribute('data-icon', $render_array['#icon']);
}
if (!empty($render_array['#label'])) {
$render_array['#attributes']
->setAttribute('data-label', $render_array['#label']);
}
}
return $render_array;
}