LocationGeolocationFieldStorage.php in Geolocation Field 8.3
File
modules/geolocation_address/src/Plugin/migrate/source/LocationGeolocationFieldStorage.php
View source
<?php
namespace Drupal\geolocation_address\Plugin\migrate\source;
use Drupal\geolocation_address\Plugin\migrate\field\Location;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\field\Plugin\migrate\source\d7\Field;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
class LocationGeolocationFieldStorage extends Field {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager) {
$configuration += [
'entity_type' => NULL,
];
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_type_manager);
}
public function query() {
$query = parent::query();
$query
->condition('fc.type', 'location');
[
'entity_type' => $entity_type,
] = $this->configuration;
if ($entity_type) {
$query
->condition('fci.entity_type', $entity_type);
}
return $query;
}
public function prepareRow(Row $row, $keep = TRUE) {
if (!parent::prepareRow($row)) {
return FALSE;
}
$geolocation_field_name = Location::getGeolocationFieldName($row
->getSourceProperty('field_name'));
$row
->setSourceProperty('geolocation_field_name', $geolocation_field_name);
return TRUE;
}
}