diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php b/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php index 3b490f0..1649700 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/field/Email.php @@ -11,7 +11,9 @@ * core = {6,7}, * type_map = { * "email" = "email" - * } + * }, + * source_module = "email", + * destination_module = "core" * ) */ class Email extends FieldPluginBase { diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php b/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php index 2e61589..f45e95d 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/EntityReference.php @@ -10,7 +10,9 @@ * type_map = { * "entityreference" = "entity_reference", * }, - * core = {7} + * core = {7}, + * source_module = "entityreference", + * destination_module = "core" * ) */ class EntityReference extends FieldPluginBase {} diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/NumberField.php b/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/NumberField.php index 9080328..cf2f456 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/NumberField.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/field/d7/NumberField.php @@ -12,7 +12,9 @@ * "number_decimal" = "decimal", * "number_float" = "float", * }, - * core = {7} + * core = {7}, + * source_module = "number", + * destination_module = "core" * ) */ class NumberField extends FieldPluginBase {} diff --git a/core/modules/datetime/src/Plugin/migrate/field/DateField.php b/core/modules/datetime/src/Plugin/migrate/field/DateField.php index 0dd56c9..c3e611a 100644 --- a/core/modules/datetime/src/Plugin/migrate/field/DateField.php +++ b/core/modules/datetime/src/Plugin/migrate/field/DateField.php @@ -14,7 +14,9 @@ * "datestamp" = "timestamp", * "datetime" = "datetime", * }, - * core = {6,7} + * core = {6,7}, + * source_module = "date", + * destination_module = "datetime" * ) */ class DateField extends FieldPluginBase { diff --git a/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php b/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php index c4e7b49..732fd3f 100644 --- a/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php +++ b/core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php @@ -16,7 +16,9 @@ * "datestamp" = "timestamp", * "datetime" = "datetime", * }, - * core = {6} + * core = {6}, + * source_module = "date", + * destination_module = "datetime" * ) * * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use diff --git a/core/modules/field/src/Plugin/migrate/source/d7/Field.php b/core/modules/field/src/Plugin/migrate/source/d7/Field.php index 9e92619..da9e037 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/Field.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/Field.php @@ -15,7 +15,7 @@ * * @MigrateSource( * id = "d7_field", - * source_module = "field" + * source_module = "field_sql_storage" * ) */ class Field extends DrupalSqlBase { diff --git a/core/modules/file/src/Plugin/migrate/field/d6/FileField.php b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php index 930c13b..87c3bfe 100644 --- a/core/modules/file/src/Plugin/migrate/field/d6/FileField.php +++ b/core/modules/file/src/Plugin/migrate/field/d6/FileField.php @@ -9,7 +9,9 @@ /** * @MigrateField( * id = "filefield", - * core = {6} + * core = {6}, + * source_module = "filefield", + * destination_module = "file" * ) */ class FileField extends FieldPluginBase { diff --git a/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php new file mode 100644 index 0000000..0a7541f --- /dev/null +++ b/core/modules/file/src/Plugin/migrate/field/d6/ImageField.php @@ -0,0 +1,60 @@ + 'file_generic', + ]; + } + + /** + * {@inheritdoc} + */ + public function getFieldFormatterMap() { + return [ + 'default' => 'file_default', + 'url_plain' => 'file_url_plain', + 'path_plain' => 'file_url_plain', + 'image_plain' => 'image', + 'image_nodelink' => 'image', + 'image_imagelink' => 'image', + ]; + } + + /** + * {@inheritdoc} + */ + public function processFieldValues(MigrationInterface $migration, $field_name, $data) { + $process = [ + 'plugin' => 'd6_field_file', + 'source' => $field_name, + ]; + $migration->mergeProcessOfProperty($field_name, $process); + } + + /** + * {@inheritdoc} + */ + public function getFieldType(Row $row) { + return $row->getSourceProperty('widget_type') == 'imagefield_widget' ? 'image' : 'file'; + } + +} diff --git a/core/modules/file/src/Plugin/migrate/field/d7/FileField.php b/core/modules/file/src/Plugin/migrate/field/d7/FileField.php index 4243d43..2d7e7ba 100644 --- a/core/modules/file/src/Plugin/migrate/field/d7/FileField.php +++ b/core/modules/file/src/Plugin/migrate/field/d7/FileField.php @@ -8,7 +8,9 @@ /** * @MigrateField( * id = "file", - * core = {7} + * core = {7}, + * source_module = "file", + * destination_module = "file" * ) */ class FileField extends D6FileField { diff --git a/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php index 7783ae2..fea19c6 100644 --- a/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php +++ b/core/modules/file/src/Plugin/migrate/field/d7/ImageField.php @@ -8,7 +8,9 @@ /** * @MigrateField( * id = "image", - * core = {7} + * core = {7}, + * source_module = "image", + * destination_module = "file" * ) */ class ImageField extends FieldPluginBase { diff --git a/core/modules/link/src/Plugin/migrate/field/d6/LinkField.php b/core/modules/link/src/Plugin/migrate/field/d6/LinkField.php index 0d03656..cb69994 100644 --- a/core/modules/link/src/Plugin/migrate/field/d6/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/field/d6/LinkField.php @@ -10,8 +10,10 @@ * id = "link", * core = {6}, * type_map = { - * "link_field" = "link" - * } + * "link_field" = "link", + * }, + * source_module = "link", + * destination_module = "link" * ) */ class LinkField extends FieldPluginBase { diff --git a/core/modules/link/src/Plugin/migrate/field/d7/LinkField.php b/core/modules/link/src/Plugin/migrate/field/d7/LinkField.php index bb71418..0dcf4c6 100644 --- a/core/modules/link/src/Plugin/migrate/field/d7/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/field/d7/LinkField.php @@ -11,7 +11,9 @@ * core = {7}, * type_map = { * "link_field" = "link" - * } + * }, + * source_module = "link", + * destination_module = "link" * ) * * This plugin provides the exact same functionality as the Drupal 6 "link" diff --git a/core/modules/migrate_drupal/src/Annotation/MigrateField.php b/core/modules/migrate_drupal/src/Annotation/MigrateField.php index ad78bc9..7192749 100644 --- a/core/modules/migrate_drupal/src/Annotation/MigrateField.php +++ b/core/modules/migrate_drupal/src/Annotation/MigrateField.php @@ -51,4 +51,26 @@ public function __construct($values) { */ public $core = []; + /** + * Identifies the system providing the data the field plugin will read. + * + * The field plugin itself determines how the value is used. For example, + * Migrate Drupal's field plugins expect source_module to be the name of a + * module that must be installed and enabled in the source database. + * + * @var string + */ + public $source_module; + + /** + * Identifies the system handling the data the destination plugin will write. + * + * The destination plugin itself determines how the value is used. For + * example, Migrate Drupal's destination plugins expect destination_module to + * be the name of a module that must be installed on the destination. + * + * @var string + */ + public $destination_module; + } diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php index fbb765f..62e6cee 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldPluginManager.php @@ -2,6 +2,10 @@ namespace Drupal\migrate_drupal\Plugin; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; +use Drupal\migrate\Plugin\MigratePluginManager; +use Drupal\migrate\Plugin\MigrationInterface; + @trigger_error('MigrateCckFieldPluginManager is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManager instead.', E_USER_DEPRECATED); /** @@ -14,4 +18,42 @@ * * @ingroup migration */ -class MigrateCckFieldPluginManager extends MigrateFieldPluginManager implements MigrateCckFieldPluginManagerInterface { } +class MigrateCckFieldPluginManager extends MigratePluginManager implements MigrateCckFieldPluginManagerInterface { + + /** + * The default version of core to use for cck field plugins. + * + * These plugins were initially only built and used for Drupal 6 cck fields. + * Having been extended for Drupal 7 with a "core" annotation, we fall back to + * Drupal 6 where none exists. + */ + const DEFAULT_CORE_VERSION = 6; + + /** + * {@inheritdoc} + */ + public function getPluginIdFromFieldType($field_type, array $configuration = [], MigrationInterface $migration = NULL) { + $core = static::DEFAULT_CORE_VERSION; + if (!empty($configuration['core'])) { + $core = $configuration['core']; + } + elseif (!empty($migration->getPluginDefinition()['migration_tags'])) { + foreach ($migration->getPluginDefinition()['migration_tags'] as $tag) { + if ($tag == 'Drupal 7') { + $core = 7; + } + } + } + + $definitions = $this->getDefinitions(); + foreach ($definitions as $plugin_id => $definition) { + if (in_array($core, $definition['core'])) { + if (array_key_exists($field_type, $definition['type_map']) || $field_type === $plugin_id) { + return $plugin_id; + } + } + } + throw new PluginNotFoundException($field_type); + } + +} diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php index 2b33c85..5741258 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateFieldPluginManager.php @@ -2,6 +2,7 @@ namespace Drupal\migrate_drupal\Plugin; +use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\migrate\Plugin\MigratePluginManager; use Drupal\migrate\Plugin\MigrationInterface; @@ -53,4 +54,17 @@ public function getPluginIdFromFieldType($field_type, array $configuration = [], throw new PluginNotFoundException($field_type); } + /** + * {@inheritdoc} + */ + public function processDefinition(&$definition, $plugin_id) { + parent::processDefinition($definition, $plugin_id); + + foreach (['core', 'source_module', 'destination_module'] as $required_property) { + if (empty($definition[$required_property])) { + throw new InvalidPluginDefinitionException($plugin_id, sprintf('The %s plugin should define the %s property.', $definition['class'], $required_property)); + } + } + } + } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php index 1579afa..4f5f080 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/NodeReference.php @@ -11,6 +11,8 @@ * type_map = { * "nodereference" = "entity_reference", * }, +* source_module = "node_reference", + * destination_module = "entity_reference", * ) */ class NodeReference extends FieldPluginBase { diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php b/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php index 11df8ec..9702cd6 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/UserReference.php @@ -11,6 +11,8 @@ * type_map = { * "userreference" = "entity_reference", * }, + * source_module = "user_reference", + * destination_module = "entity_reference", * ) */ class UserReference extends FieldPluginBase { diff --git a/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6FileField.php b/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6FileField.php index acb9d9c..bb5e5fd 100644 --- a/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6FileField.php +++ b/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6FileField.php @@ -10,7 +10,9 @@ * core = {6}, * type_map = { * "file" = "file" - * } + * }, + * source_module = "foo", + * destination_module = "bar", * ) */ class D6FileField extends FieldPluginBase {} diff --git a/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6NoCoreVersionSpecified.php b/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6NoCoreVersionSpecified.php index 39f109b..00e2fbf 100644 --- a/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6NoCoreVersionSpecified.php +++ b/core/modules/migrate_drupal/tests/modules/migrate_field_plugin_manager_test/src/Plugin/migrate/field/D6NoCoreVersionSpecified.php @@ -6,10 +6,9 @@ /** * @MigrateField( - * id = "d6_no_core_version_specified" + * id = "d6_no_core_version_specified", + * source_module = "foo", + * destination_module = "bar", * ) */ -class D6NoCoreVersionSpecified extends FieldPluginBase { - - -} +class D6NoCoreVersionSpecified extends FieldPluginBase { } diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index be0e264..061c2f1 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -2,13 +2,16 @@ namespace Drupal\migrate_drupal_ui\Form; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Datetime\DateFormatterInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Url; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; use Drupal\migrate_drupal_ui\Batch\MigrateUpgradeImportBatch; use Drupal\migrate_drupal\MigrationConfigurationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -49,6 +52,20 @@ class MigrateUpgradeForm extends ConfirmFormBase { protected $pluginManager; /** + * The field migrate plugin manager. + * + * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface + */ + protected $fieldPluginManager; + + /** + * The modue handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * Constructs the MigrateUpgradeForm. * * @param \Drupal\Core\State\StateInterface $state @@ -59,12 +76,18 @@ class MigrateUpgradeForm extends ConfirmFormBase { * The renderer service. * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager * The migration plugin manager. + * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager + * The field plugin manager. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The ID map migration plugin manager. */ - public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, RendererInterface $renderer, MigrationPluginManagerInterface $plugin_manager) { + public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, RendererInterface $renderer, MigrationPluginManagerInterface $plugin_manager, MigrateFieldPluginManagerInterface $field_plugin_manager, ModuleHandlerInterface $module_handler) { $this->state = $state; $this->dateFormatter = $date_formatter; $this->renderer = $renderer; $this->pluginManager = $plugin_manager; + $this->fieldPluginManager = $field_plugin_manager; + $this->moduleHandler = $module_handler; } /** @@ -75,7 +98,9 @@ public static function create(ContainerInterface $container) { $container->get('state'), $container->get('date.formatter'), $container->get('renderer'), - $container->get('plugin.manager.migration') + $container->get('plugin.manager.migration'), + $container->get('plugin.manager.migrate.field'), + $container->get('module_handler') ); } @@ -470,6 +495,25 @@ public function buildConfirmForm(array $form, FormStateInterface $form_state) { $table_data[$source_module][$destination_module][$migration_id] = $migration->label(); } } + + // Now get the field migrations. + $field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions(); + foreach ($field_types as $field_type => $value) { + try { + $plugin_id = $this->fieldPluginManager->getPluginIdFromFieldType($field_type, ['core' => $version]); + $field_definition = $this->fieldPluginManager->getDefinition($plugin_id); + $field_plugin_id = $field_definition['id']; + $source_module = $field_definition['source_module']; + $destination_module = $field_definition['destination_module']; + if (($destination_module == 'core') || $this->moduleHandler->moduleExists($destination_module)) { + $table_data[$source_module][$destination_module][$field_plugin_id] = $field_plugin_id; + } + } + catch (PluginNotFoundException $ex) { + continue; + } + } + // Sort the table by source module names and within that destination // module names. ksort($table_data); @@ -481,6 +525,11 @@ public function buildConfirmForm(array $form, FormStateInterface $form_state) { $system_data = $form_state->get('system_data'); $unmigrated_source_modules = array_diff_key($system_data['module'], $table_data); + // Remove core profiles from the list. + foreach (['standard', 'minimal'] as $profile) { + unset($unmigrated_source_modules[$profile]); + } + // Missing migrations. $form['missing_module_list_title'] = [ '#type' => 'item', diff --git a/core/modules/options/src/Plugin/migrate/field/d6/OptionWidgetsField.php b/core/modules/options/src/Plugin/migrate/field/d6/OptionWidgetsField.php new file mode 100644 index 0000000..b6b5516 --- /dev/null +++ b/core/modules/options/src/Plugin/migrate/field/d6/OptionWidgetsField.php @@ -0,0 +1,15 @@ +