You are here

protected function Geofield::prepareValue in Geofield 8

Prepares a single value.

Parameters

int $delta: The field delta.

array $values: The values.

Overrides FieldTargetBase::prepareValue

1 call to Geofield::prepareValue()
Geofield::prepareValues in src/Feeds/Target/Geofield.php
Prepares the the values that will be mapped to an entity.

File

src/Feeds/Target/Geofield.php, line 122

Class

Geofield
Defines a geofield field mapper.

Namespace

Drupal\geofield\Feeds\Target

Code

protected function prepareValue($delta, array &$values) {

  // Here is been preparing values for Lat/Lon coordinates.
  foreach ($values as $column => $value) {
    if (in_array($column, [
      'lat',
      'lon',
    ])) {
      $separated_coordinates = explode(" ", $value);
      $values[$column] = [];
      foreach ($separated_coordinates as $coordinate) {
        $values[$column][] = (double) $coordinate;
      }
    }
  }

  // Latitude and Longitude should be a pair, if not throw EmptyFeedException.
  if (count($values['lat']) != count($values['lon'])) {
    throw new EmptyFeedException('Latitude and Longitude should be a pair. Change your file and import again.');
  }
}