ReverseGeoFieldExportFormatter.php in REST Views 8
File
modules/rest_views_geo/src/Plugin/Field/FieldFormatter/ReverseGeoFieldExportFormatter.php
View source
<?php
namespace Drupal\rest_views_geo\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\rest_views\SerializedData;
class ReverseGeoFieldExportFormatter extends FormatterBase {
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;
}
}