By mikelutz on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.7.x
Introduced in version:
8.7.0
Issue links:
Description:
Summary
A new service has been added ('migrate_drupal.field_discovery') to simplify the process of detecting and adding appropriate field process arrays for content migrations of Drupal 6 nodes and Drupal 7 fieldable entities. This service contains the method addFields(MigrationInterface $migration, $entity_type, $bundle = '') and detects and adds the appropriate field process arrays to the passed in migration.
Before
// Read all field instance definitions in the source database.
$fields = [];
try {
$source_plugin = static::getSourcePlugin('d6_field_instance');
$source_plugin->checkRequirements();
foreach ($source_plugin as $row) {
$fields[$row->getSourceProperty('type_name')][$row->getSourceProperty('field_name')] = $row->getSource();
}
}
catch (RequirementsException $e) {
// If checkRequirements() failed then the content module did not exist and
// we do not have any fields. Therefore, $fields will be empty and
// below we'll create a migration just for the node properties.
}
try {
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
if (isset($fields[$node_type])) {
foreach ($fields[$node_type] as $field_name => $info) {
$field_type = $info['type'];
try {
$plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration);
if (!isset($this->fieldPluginCache[$field_type])) {
$this->fieldPluginCache[$field_type] = $this->fieldPluginManager->createInstance($plugin_id, ['core' => 6], $migration);
}
$this->fieldPluginCache[$field_type]
->processFieldValues($migration, $field_name, $info);
}
catch (PluginNotFoundException $ex) {
try {
$plugin_id = $this->cckPluginManager->getPluginIdFromFieldType($field_type, ['core' => 6], $migration);
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($plugin_id, ['core' => 6], $migration);
}
$this->cckPluginCache[$field_type]
->processCckFieldValues($migration, $field_name, $info);
}
catch (PluginNotFoundException $ex) {
$migration->setProcessOfProperty($field_name, $field_name);
}
}
}
}
$this->derivatives[$node_type] = $migration->getPluginDefinition();
}
}
After:
try {
foreach ($node_types as $row) {
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
\Drupal::service('migrate_drupal.field_discovery')->addFields($migration, 'node', $node_type);
$this->derivatives[$node_type] = $migration->getPluginDefinition();
}
}
Impacts:
Module developers