protected function GeolocationMapFormatterBase::getLocations in Geolocation Field 8.3
Get renderable locations from field items.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: Field items.
Return value
array Renderable locations.
1 call to GeolocationMapFormatterBase::getLocations()
- GeolocationMapFormatterBase::viewElements in src/
Plugin/ Field/ FieldFormatter/ GeolocationMapFormatterBase.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ GeolocationMapFormatterBase.php, line 401
Class
- GeolocationMapFormatterBase
- Plugin base for Map based formatters.
Namespace
Drupal\geolocation\Plugin\Field\FieldFormatterCode
protected function getLocations(FieldItemListInterface $items) {
$settings = $this
->getSettings();
$locations = [];
foreach ($items as $delta => $item) {
foreach ($this->dataProvider
->getPositionsFromItem($item) as $item_position) {
if (empty($item_position)) {
continue;
}
$title = $this->dataProvider
->replaceFieldItemTokens($settings['title'], $item);
if (empty($title)) {
$title = $item_position['lat'] . ', ' . $item_position['lng'];
}
$location = [
'#type' => 'geolocation_map_location',
'#title' => $title,
'#disable_marker' => empty($settings['set_marker']),
'#coordinates' => [
'lat' => $item_position['lat'],
'lng' => $item_position['lng'],
],
'#weight' => $delta,
];
if ($settings['show_label']) {
$location['#label'] = $title;
}
if (!empty($settings['info_text']['value']) && !empty($settings['info_text']['format'])) {
$location['content'] = [
'#type' => 'processed_text',
'#text' => $this->dataProvider
->replaceFieldItemTokens($settings['info_text']['value'], $item),
'#format' => $settings['info_text']['format'],
];
}
$locations[] = $location;
}
$locations = array_merge($this->dataProvider
->getLocationsFromItem($item), $locations);
$locations = array_merge($this->dataProvider
->getShapesFromItem($item), $locations);
}
return $locations;
}