GeofieldLatLon.php in Geofield 8
File
src/Plugin/migrate/process/GeofieldLatLon.php
View source
<?php
namespace Drupal\geofield\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\geofield\WktGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GeofieldLatLon extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $wktGenerator;
public function __construct(array $configuration, $plugin_id, $plugin_definition, WktGeneratorInterface $wkt_generator) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->wktGenerator = $wkt_generator;
}
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'));
}
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$value = array_map('floatval', $value);
list($lat, $lon) = $value;
if (empty($lat) || empty($lon)) {
return NULL;
}
return $this->wktGenerator
->WktBuildPoint([
$lon,
$lat,
]);
}
}
Classes
Name |
Description |
GeofieldLatLon |
Process latitude and longitude and return the value for the D8 geofield. |