public function MultiversionMigration::getFieldMap in Multiversion 8
Helper method to fetch the field map for an entity type.
Parameters
EntityTypeInterface $entity_type:
string $op:
string $action:
Return value
array
Overrides MultiversionMigrationInterface::getFieldMap
File
- src/
MultiversionMigration.php, line 212
Class
Namespace
Drupal\multiversionCode
public function getFieldMap(EntityTypeInterface $entity_type, $op, $action) {
$map = [];
// For some reasons it sometimes doesn't work if injecting the service.
$entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
$entity_type_bundle_info
->clearCachedBundles();
$bundle_info = $entity_type_bundle_info
->getBundleInfo($entity_type
->id());
foreach ($bundle_info as $bundle_id => $bundle_label) {
// For some reasons it sometimes doesn't work if injecting the service.
$entity_field_manager = \Drupal::service('entity_field.manager');
$entity_field_manager
->clearCachedFieldDefinitions();
$definitions = $entity_field_manager
->getFieldDefinitions($entity_type
->id(), $bundle_id);
foreach ($definitions as $definition) {
$name = $definition
->getName();
// We don't want our own fields to be part of the migration mapping or
// they would get assigned NULL instead of default values.
if (!in_array($name, [
'workspace',
'_deleted',
'_rev',
])) {
$map[$name] = $name;
}
}
}
// @todo Implement hook/alter functionality here.
if (MultiversionManager::OP_DISABLE == $op) {
$parent_key = 'parent';
if ('menu_link_content' == $entity_type
->id() && isset($map[$parent_key])) {
$map[$parent_key] = [
[
'plugin' => 'splice',
'delimiter' => ':',
'source' => $parent_key,
'strict' => FALSE,
'slice' => 2,
],
];
}
}
return $map;
}