D7LocationFieldDeriver.php in Geolocation Field 8.3
File
modules/geolocation_address/src/Plugin/migrate/D7LocationFieldDeriver.php
View source
<?php
namespace Drupal\geolocation_address\Plugin\migrate;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\PluginBase;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class D7LocationFieldDeriver extends DeriverBase {
use MigrationDeriverTrait;
public function getDerivativeDefinitions($base_plugin_definition) {
$source = $this
->getSourcePlugin($base_plugin_definition['source']['plugin']);
assert($source instanceof DrupalSqlBase);
try {
$source
->checkRequirements();
} catch (RequirementsException $e) {
return $this->derivatives;
}
$derivatives = [];
try {
foreach ($source as $row) {
assert($row instanceof Row);
$entity_type = $row
->getSourceProperty('entity_type');
$bundle = $row
->getSourceProperty('bundle');
$values = [
'entity_type' => $entity_type,
'bundle' => $bundle,
];
$derivative_id = $bundle !== NULL ? $entity_type . PluginBase::DERIVATIVE_SEPARATOR . $bundle : $entity_type;
$derivatives[$derivative_id] = $values;
}
} catch (\Exception $e) {
return $this->derivatives;
}
foreach ($derivatives as $derivative_id => $values) {
[
'entity_type' => $entity_type,
'bundle' => $bundle,
] = $values;
$derivative_definition = $base_plugin_definition;
$derivative_definition['source']['entity_type'] = $entity_type;
if ($bundle !== NULL) {
$derivative_definition['source']['bundle'] = $bundle;
}
$migration_required_deps = $derivative_definition['migration_dependencies']['required'] ?? [];
$storage_migration_dep_key = array_search('d7_field_location', $migration_required_deps);
if ($storage_migration_dep_key !== FALSE) {
$derivative_definition['migration_dependencies']['required'][$storage_migration_dep_key] .= PluginBase::DERIVATIVE_SEPARATOR . $entity_type;
}
$instance_migration_dep_key = array_search('d7_field_instance_location', $migration_required_deps);
if ($instance_migration_dep_key !== FALSE) {
$derivative_definition['migration_dependencies']['required'][$instance_migration_dep_key] .= implode(PluginBase::DERIVATIVE_SEPARATOR, array_filter([
$entity_type,
$bundle,
]));
}
$this->derivatives[$derivative_id] = $derivative_definition;
}
return $this->derivatives;
}
}