GeoField.php in Geofield 8
File
src/Plugin/migrate/process/GeoField.php
View source
<?php
namespace Drupal\geofield\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\geofield\GeoPHP\GeoPHPInterface;
class GeoField extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $geoPhpWrapper;
public function __construct(array $configuration, $plugin_id, $plugin_definition, GeoPHPInterface $geo_php) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->geoPhpWrapper = $geo_php;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('geofield.geophp'));
}
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
return [
'value' => $this
->toWtk($value['geom']),
'geo_type' => $value['geo_type'],
'lat' => $value['lat'],
'lon' => $value['lon'],
'left' => $value['left'],
'top' => $value['top'],
'right' => $value['right'],
'bottom' => $value['bottom'],
'geohash' => $value['geohash'],
];
}
protected function toWtk($geom) {
$geometry = $this->geoPhpWrapper
->load($geom);
if ($geometry instanceof \Geometry) {
return $geometry
->out('wkt');
}
return '';
}
}
Classes
Name |
Description |
GeoField |
Maps D7 geofield values to new the geofield values. |