protected function Geofield::prepareValues in Geofield 8
Prepares the the values that will be mapped to an entity.
Parameters
array $values: The values.
Overrides FieldTargetBase::prepareValues
File
- src/
Feeds/ Target/ Geofield.php, line 81
Class
- Geofield
- Defines a geofield field mapper.
Namespace
Drupal\geofield\Feeds\TargetCode
protected function prepareValues(array $values) {
$results = [];
$coordinates = [];
foreach ($values as $delta => $columns) {
try {
$this
->prepareValue($delta, $columns);
foreach ($columns as $column => $value) {
// Add Lat/Lon Coordinates.
if (in_array($column, [
'lat',
'lon',
])) {
foreach ($value as $item) {
$coordinates[$column][] = $item;
}
}
// Raw Geometry value (i.e. WKT or GeoJson).
if ($column == 'value') {
$results[]['value'] = $value;
}
}
} catch (EmptyFeedException $e) {
$this->messenger
->addError($e
->getMessage());
return FALSE;
}
}
// Transform Lat/Lon Coordinates couples into WKT Points.
if (!empty($coordinates)) {
$count_of_coordinates = count($coordinates['lat']);
for ($i = 0; $i < $count_of_coordinates; $i++) {
$results[]['value'] = "POINT (" . $coordinates['lon'][$i] . " " . $coordinates['lat'][$i] . ")";
}
}
return $results;
}