public function MigrateGeofieldFieldHandler::prepare in Geofield 7.2
Implements MigrateFieldHandler::prepare().
Parameters
object $entity: Entity which is going to embed the field.
array $field_info: Info for the field.
array $instance: Instance info for the field.
array $values: Values to be stored in the field.
File
- ./
geofield.migrate.inc, line 86 - Support for migration into Geofield fields.
Class
- MigrateGeofieldFieldHandler
- Primary value passed to this field must be the Geometry type string.
Code
public function prepare($entity, array $field_info, array $instance, array $values) {
$arguments = array();
if (isset($values['arguments'])) {
$arguments = array_filter($values['arguments']);
unset($values['arguments']);
}
$language = $this
->getFieldLanguage($entity, $field_info, $arguments);
// Setup a Field API array for saving.
// Use https://drupal.org/node/1854188 as a guide for geoPHP field type.
$delta = 0;
foreach ($values as $value) {
$input_format = $arguments['input_format'];
if (isset($input_format)) {
$return[$language][$delta]['input_format'] = $arguments['input_format'];
switch ($input_format) {
case 'wkt':
// Well known text - array of WKT data.
$return[$language][$delta]['geom'] = $value;
break;
case 'json':
// GeoJSON - requires array of JSON data.
$return[$language][$delta]['geom'] = $value;
break;
case 'lat/lon':
// Lat/Long - requires array of lat and lon source fields.
$return[$language][$delta]['geom']['lat'] = $arguments['lat'];
$return[$language][$delta]['geom']['lon'] = $arguments['lon'];
break;
case 'bounds':
// Delimited area marked by an array of left (lon), top (lat), right
// (long), bottom (lat) values.
$return[$language][$delta]['geom']['left'] = $arguments['left'];
$return[$language][$delta]['geom']['top'] = $arguments['top'];
$return[$language][$delta]['geom']['right'] = $arguments['right'];
$return[$language][$delta]['geom']['bottom'] = $arguments['bottom'];
break;
}
}
else {
// If no input format specified the $value is assumed to represent a
// a WKT value or another format that can be parsed by geoPHP.
$return[$language][$delta]['geom'] = $value;
}
$delta++;
}
return isset($return) ? $return : NULL;
}