geofield.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Primary value passed to this field must be the geometry type of the geofield: Point, LineString, Polygon
  4. *
  5. * Arguments are used to specify all the other values:
  6. * 'wkt' - Well Known Text
  7. * 'lat' - Latitude.
  8. * 'lon' - Longitude
  9. * 'top' - Top Latitude
  10. * 'bottom' - Bottom Latitude
  11. * 'right' - Right Longitude
  12. * 'left' - Left Longitude
  13. *
  14. * Add the source field mappings to the argument array then add null mappings to
  15. * avoid having fields flagged as as unmapped:
  16. * @code
  17. * $geo_arguments = array(
  18. * 'lat' => array('source_field' => 'source_field_latidute'),
  19. * 'lon' => array('source_field' => 'source_field_longitude'),
  20. * );
  21. * // The geometry type should be passed in as the primary value.
  22. * $this->addFieldMapping('field_geofield_dest', 'field_source_geotype')
  23. * ->arguments($geo_arguments);
  24. * // Since the excerpt is mapped via an argument, add a null mapping so it's
  25. * // not flagged as unmapped.
  26. * $this->addFieldMapping(NULL, 'source_field_latitude');
  27. * $this->addFieldMapping(NULL, 'source_field_longitude');
  28. * @endcode
  29. */
  30. class MigrateGeoFieldHandler extends MigrateFieldHandler {
  31. public function __construct() {
  32. $this->registerTypes(array('geofield'));
  33. }
  34. public function prepare($entity, array $field_info, array $instance, array $values) {
  35. $arguments = array();
  36. if (isset($values['arguments'])) {
  37. $arguments = array_filter($values['arguments']);
  38. unset($values['arguments']);
  39. }
  40. $language = $this->getFieldLanguage($entity, $field_info, $arguments);
  41. // Setup the standard Field API array for saving.
  42. $delta = 0;
  43. foreach ($values as $value) {
  44. $return[$language][$delta] = array('geo_type' => $value) + array_intersect_key($arguments, $field_info['columns']);
  45. $delta++;
  46. }
  47. return isset($return) ? $return : NULL;
  48. }
  49. }