diff --git a/src/Plugin/migrate/cckfield/Geofield.php b/src/Plugin/migrate/cckfield/Geofield.php index 74255c7..cfdfade 100644 --- a/src/Plugin/migrate/cckfield/Geofield.php +++ b/src/Plugin/migrate/cckfield/Geofield.php @@ -61,8 +61,17 @@ class Geofield extends CckFieldPluginBase { */ public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { $migration->mergeProcessOfProperty($field_name, [ - 'plugin' => 'geofield_latlon', + 'plugin' => 'iterator', 'source' => $field_name, + 'process' => [ + [ + 'plugin' => 'geofield_latlon', + 'source' => [ + 'lat', + 'lon', + ], + ], + ], ]); } diff --git a/src/Plugin/migrate/process/GeofieldLatLon.php b/src/Plugin/migrate/process/GeofieldLatLon.php index a8fff91..f7375d0 100644 --- a/src/Plugin/migrate/process/GeofieldLatLon.php +++ b/src/Plugin/migrate/process/GeofieldLatLon.php @@ -6,12 +6,9 @@ */ namespace Drupal\geofield\Plugin\migrate\process; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\geofield\WktGeneratorInterface; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Process latitude and longitude and return the value for the D8 geofield. @@ -20,48 +17,21 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * id = "geofield_latlon" * ) */ -class GeofieldLatLon extends ProcessPluginBase implements ContainerFactoryPluginInterface { - - /** - * The Wkt generator service. - * - * @var \Drupal\geofield\WktGeneratorInterface - */ - protected $wktGenerator; - - /** - * Create an instance of the GeofieldLatLon process plugin. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, WktGeneratorInterface $wktGenerator) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->wktGenerator = $wktGenerator; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('geofield.wkt_generator') - ); - } +class GeofieldLatLon extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - if (isset($value['lat']) && isset($value['lon'])) { - $lat = $value['lat']; - $lon = $value['lon']; - } - else { - list($lat, $lon) = $value; - } + list($lat, $lon) = $value; + + if (empty($lat) || empty($lon)) { + return NULL; + } + + $lonlat = \Drupal::service('geofield.wkt_generator')->WktBuildPoint(array($lon, $lat)); - return empty($lat) || empty($lon) ? NULL : $this->wktGenerator->WktBuildPoint(array($lon, $lat)); + return $lonlat; } }