public function LocationToGeolocation::transform in Geolocation Field 8.3
Performs the associated process.
Parameters
mixed $value: The value to be transformed.
\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.
\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.
string $destination_property: The destination property currently worked on. This is only used together with the $row above.
Return value
string|array The newly transformed value.
Overrides ProcessPluginBase::transform
File
- src/
Plugin/ migrate/ process/ LocationToGeolocation.php, line 62
Class
- LocationToGeolocation
- Process plugin that converts D7 location field values to D8|D9 geolocation.
Namespace
Drupal\geolocation\Plugin\migrate\processCode
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($value) || empty($value['lid'])) {
// Empty field value.
return NULL;
}
$source_plugin = $this->migration
->getSourcePlugin();
assert($source_plugin instanceof DrupalSqlBase);
$source_database = $source_plugin
->getDatabase();
try {
$location_result = $source_database
->select('location', 'l')
->fields('l')
->condition('l.lid', $value['lid'])
->execute()
->fetchAllAssoc('lid', \PDO::FETCH_ASSOC);
if (count($location_result) === 1) {
$location_raw = reset($location_result);
[
'latitude' => $lat,
'longitude' => $lng,
] = $location_raw;
// The "0.000000" values are the default values in Drupal 7, but that's
// also a valid coordinate. Anyway, let's assume that it means the field
// is empty.
return (string) $lat !== '0.000000' && (string) $lng !== '0.000000' ? [
'lat' => $lat,
'lng' => $lng,
] : NULL;
}
} catch (DatabaseExceptionWrapper $e) {
}
return NULL;
}