public function ReverseGeoFieldExportFormatter::viewElements in REST Views 8
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/ ReverseGeoFieldExportFormatter.php, line 25
Class
- ReverseGeoFieldExportFormatter
- Export a Geo field.
Namespace
Drupal\rest_views_geo\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$data = [
'address1' => $item->address1,
'address2' => $item->address2,
'city' => $item->city,
'postcode' => $item->postcode,
'latitude' => $item->lat,
'longitude' => $item->lng,
];
$elements[$delta] = [
'#type' => 'data',
'#data' => SerializedData::create($data),
];
}
return $elements;
}