public function D7LocationFieldDeriver::getDerivativeDefinitions in Geolocation Field 8.3
Gets the definition of all derivatives of a base plugin.
Parameters
array $base_plugin_definition: The definition array of the base plugin.
Return value
array An array of full derivative definitions keyed on derivative id.
Overrides DeriverBase::getDerivativeDefinitions
See also
getDerivativeDefinition()
File
- modules/
geolocation_address/ src/ Plugin/ migrate/ D7LocationFieldDeriver.php, line 26
Class
- D7LocationFieldDeriver
- Deriver geolocation field config migrations of Drupal 7 Location CCK fields.
Namespace
Drupal\geolocation_address\Plugin\migrateCode
public function getDerivativeDefinitions($base_plugin_definition) {
$source = $this
->getSourcePlugin($base_plugin_definition['source']['plugin']);
assert($source instanceof DrupalSqlBase);
try {
$source
->checkRequirements();
} catch (RequirementsException $e) {
// If the source plugin requirements failed, that means we do not have a
// Drupal source database configured - there is nothing to generate.
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;
}
// Using the same derivative for field storage and field instance
// migrations. Field storage migrations are always derived by their parent
// entity type. Field instance migrations are derived by parent entity type
// and by bundle. For bundle-less entities (like user), the bundle will be
// the entity type, like "d7_field_location_instance:user:user".
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;
}
// Process dependencies.
$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;
}