public function GeolocationLatLngExportFormatter::viewElements in REST Views 2.0.x
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- modules/
rest_views_geo/ src/ Plugin/ Field/ FieldFormatter/ GeolocationLatLngExportFormatter.php, line 26
Class
- GeolocationLatLngExportFormatter
- Plugin implementation of the 'geolocation_latlng' export formatter.
Namespace
Drupal\rest_views_geo\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) : array {
$elements = [];
foreach ($items as $delta => $item) {
$data = [
'lat' => $item->lat,
'lng' => $item->lng,
];
$elements[$delta] = [
'#type' => 'data',
'#data' => SerializedData::create($data),
];
}
return $elements;
}