reverted: --- b/core/modules/migrate_drupal_ui/migrate_drupal_ui.services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - migrate_drupal_ui.providers: - class: Drupal\migrate_drupal_ui\MigrationProviders - arguments: - - migration diff -u b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php --- b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -9,9 +9,9 @@ use Drupal\Core\State\StateInterface; use Drupal\Core\Url; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate\Plugin\MigrationProviderInterface; use Drupal\migrate_drupal_ui\Batch\MigrateUpgradeImportBatch; use Drupal\migrate_drupal\MigrationConfigurationTrait; -use Drupal\migrate_drupal_ui\MigrationProviders; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -50,13 +50,6 @@ protected $pluginManager; /** - * The migration provider service. - * - * @var \Drupal\migrate_drupal_ui\MigrationProviders - */ - protected $migrationProviders; - - /** * Constructs the MigrateUpgradeForm. * * @param \Drupal\Core\State\StateInterface $state @@ -67,15 +60,12 @@ * The renderer service. * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager * The migration plugin manager. - * @param \Drupal\migrate_drupal_ui\MigrationProviders $migration_providers - * The migration provider service. */ - public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, RendererInterface $renderer, MigrationPluginManagerInterface $plugin_manager, MigrationProviders $migration_providers) { + public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, RendererInterface $renderer, MigrationPluginManagerInterface $plugin_manager) { $this->state = $state; $this->dateFormatter = $date_formatter; $this->renderer = $renderer; $this->pluginManager = $plugin_manager; - $this->migrationProviders = $migration_providers; } /** @@ -86,8 +76,7 @@ $container->get('state'), $container->get('date.formatter'), $container->get('renderer'), - $container->get('plugin.manager.migration'), - $container->get('migrate_drupal_ui.providers') + $container->get('plugin.manager.migration') ); } @@ -413,21 +402,30 @@ $table_data = []; foreach ($migrations as $migration) { - $providers = $this->migrationProviders->getProviders($migration); - list($source_module, $destination_module) = $providers; $migration_id = $migration->getPluginId(); - if (!$source_module) { + + $source_provider = NULL; + $source_plugin = $migration->getSourcePlugin(); + if ($source_plugin instanceof MigrationProviderInterface) { + $source_provider = $source_plugin->getProvider(); + } + if (!$source_provider) { drupal_set_message($this->t('Source provider not found for @migration_id.', ['@migration_id' => $migration_id]), 'error'); } - if (!$destination_module) { + + $destination_provider = NULL; + $destination_plugin = $migration->getDestinationPlugin(); + if ($destination_plugin instanceof MigrationProviderInterface) { + $destination_provider = $destination_plugin->getProvider(); + } + if (!$destination_provider) { drupal_set_message($this->t('Destination provider not found for @migration_id.', ['@migration_id' => $migration_id]), 'error'); } - if ($source_module && $destination_module) { - $table_data[$source_module][$destination_module][$migration_id] = $migration->label(); + if ($source_provider && $destination_provider) { + $table_data[$source_provider][$destination_provider][$migration_id] = $migration->label(); } } - // Sort the table by source module names and within that destination // module names. ksort($table_data); reverted: --- b/core/modules/migrate_drupal_ui/src/MigrationProviders.php +++ /dev/null @@ -1,56 +0,0 @@ -getSourceConfiguration(); - $source_module = (!empty($source_configuration['provider'])) ? $source_configuration['provider'] : NULL; - if (!$source_module) { - // Get the source_provider from the plugin definition. - $plugin_definition = $migration->getSourcePlugin()->getPluginDefinition(); - $source_module = (!empty($plugin_definition['source_provider'])) ? $plugin_definition['source_provider'] : NULL; - } - - // Determine the destination provider, looking in configuration first. - $destination_configuration = $migration->getDestinationConfiguration(); - $destination_module = (!empty($destination_configuration['provider'])) ? $destination_configuration['provider'] : NULL; - if (!$destination_module) { - $destination_plugin = $migration->getDestinationPlugin(); - if ($destination_plugin->getPluginId() == 'config') { - // For configuration destinations pull out the module name from the - // configuration destination string. - $configuration_destination = (!empty($destination_configuration['config_name'])) ? $destination_configuration['config_name'] : NULL; - if ($configuration_destination) { - $destination_module = explode('.', $configuration_destination, 2)[0]; - } - } - else { - // If not a config destination, the destination module is simply - // the provider of the plugin. - $destination_module = $destination_plugin->getPluginDefinition()['provider']; - } - } - return ([$source_module, $destination_module]); - } - -} reverted: --- b/core/modules/migrate_drupal_ui/tests/src/Kernel/ProvidersExistTest.php +++ /dev/null @@ -1,62 +0,0 @@ -container->get('module_handler'); - $modules = $this->coreModuleListDataProvider(); - $modules_enabled = $module_handler->getModuleList(); - $modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled)); - $this->enableModules($modules_to_enable); - - /** @var \Drupal\migrate\Plugin\MigrationPluginManager $manager */ - $pluginManager = $this->container->get('plugin.manager.migration'); - $migrationProviders = $this->container->get('migrate_drupal_ui.providers'); - // Get all the migrations - $migrations = $pluginManager->createInstances(array_keys($pluginManager->getDefinitions())); - /** @var \Drupal\migrate\Plugin\Migration $migration */ - foreach ($migrations as $migration) { - $providers = $migrationProviders->getProviders($migration); - list($source_module, $destination_module) = $providers; - $migration_id = $migration->getPluginId(); - if ($migration_id == 'provider_test') { - $this->assertFalse($source_module, new FormattableMarkup('Source provider not found for @migration_id.', ['@migration_id' => $migration_id])); - $this->assertFalse($destination_module, new FormattableMarkup('Destination provider not found for @migration_id.', ['@migration_id' => $migration_id])); - } - elseif ($migration_id == 'provider_no_annotation') { - $this->assertFalse($source_module, new FormattableMarkup('Source provider not found for @migration_id.', ['@migration_id' => $migration_id])); - $this->assertTrue($destination_module, new FormattableMarkup('Destination provider found for @migration_id.', ['@migration_id' => $migration_id])); - } - else { - $this->assertTrue($source_module, new FormattableMarkup('Source provider found for @migration_id.', ['@migration_id' => $migration_id])); - $this->assertTrue($destination_module, new FormattableMarkup('Destination provider found for @migration_id.', ['@migration_id' => $migration_id])); - } - // Destination provider can't be migrate or migrate_drupal or migrate_drupal_ui - $invalid_destinations = ['migrate', 'migrate_drupal', 'migrate_drupal_ui']; - $this->assertNotContains($destination_module, $invalid_destinations, new FormattableMarkup('Invalid destination for @migration_id.', ['@migration_id' => $migration_id])); - } - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/Plugin/MigrationProviderInterface.php @@ -0,0 +1,15 @@ +migration->getDestinationConfiguration(); + // For configuration destinations pull out the module name from the + // configuration destination string. + $configuration_destination = (!empty($destination_configuration['config_name'])) ? $destination_configuration['config_name'] : NULL; + if ($configuration_destination) { + $destination_module = explode('.', $configuration_destination, 2)[0]; + } + else { + $destination_module = NULL; + } + return $destination_module; + } + } only in patch2: unchanged: --- a/core/modules/migrate/src/Plugin/migrate/destination/DestinationBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/DestinationBase.php @@ -8,6 +8,7 @@ use Drupal\migrate\Plugin\MigrateDestinationInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\RequirementsInterface; +use Drupal\migrate\Plugin\MigrationProviderInterface; /** * Base class for migrate destination classes. @@ -19,7 +20,7 @@ * * @ingroup migration */ -abstract class DestinationBase extends PluginBase implements MigrateDestinationInterface, RequirementsInterface { +abstract class DestinationBase extends PluginBase implements MigrateDestinationInterface, RequirementsInterface, MigrationProviderInterface { /** * Indicates whether the destination can be rolled back. @@ -110,4 +111,29 @@ protected function setRollbackAction(array $id_map, $update_action = MigrateIdMa } } + /** + * Gets the destination provider. + * + * @return string | NULL + * The destination provider. + */ + public function getProvider() { + $destination_module = (!empty($this->configuration['provider'])) ? $this->configuration['provider'] : NULL; + if (!$destination_module) { + if ($this->pluginId == 'config') { + // For config destinations get the module name from the configuration. + $configuration = (!empty($this->configuration['config_name'])) ? $this->configuration['config_name'] : NULL; + if ($configuration) { + $destination_module = explode('.', $configuration, 2)[0]; + } + } + else { + // If not a config destination, the destination module is simply + // the provider of the plugin. + $destination_module = $this->pluginDefinition['provider']; + } + } + return $destination_module; + } + } only in patch2: unchanged: --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -11,6 +11,7 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Row; +use Drupal\migrate\Plugin\MigrationProviderInterface; /** * The base class for all source plugins. @@ -22,7 +23,7 @@ * * @ingroup migration */ -abstract class SourcePluginBase extends PluginBase implements MigrateSourceInterface, RollbackAwareInterface { +abstract class SourcePluginBase extends PluginBase implements MigrateSourceInterface, RollbackAwareInterface, MigrationProviderInterface { /** * The module handler service. @@ -541,4 +542,19 @@ public function postRollback(MigrateRollbackEvent $event) { $this->saveHighWater(NULL); } + /** + * Gets the source provider. + + * @return string | NULL + * The source provider which is expected to be the name of module in the + * source database. + */ + public function getProvider() { + $source_module = (!empty($this->configuration['provider'])) ? $this->configuration['provider'] : NULL; + if (!$source_module) { + $source_module = (!empty($this->pluginDefinition['source_provider'])) ? $this->pluginDefinition['source_provider'] : NULL; + } + return $source_module; + } + } only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/tests/src/Kernel/Plugin/ProvidersExistTest.php @@ -0,0 +1,69 @@ +container->get('module_handler'); + $modules = $this->coreModuleListDataProvider(); + $modules_enabled = $module_handler->getModuleList(); + $modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled)); + $this->enableModules($modules_to_enable); + + /** @var \Drupal\migrate\Plugin\MigrationPluginManager $manager */ + $pluginManager = $this->container->get('plugin.manager.migration'); + // Get all the migrations + $migrations = $pluginManager->createInstances(array_keys($pluginManager->getDefinitions())); + /** @var \Drupal\migrate\Plugin\Migration $migration */ + foreach ($migrations as $migration) { + $source_provider = NULL; + $destination_provider = NULL; + $source_plugin = $migration->getSourcePlugin(); + if ($source_plugin instanceof MigrationProviderInterface) { + $source_provider = $source_plugin->getProvider(); + } + $destination_plugin = $migration->getDestinationPlugin(); + if ($destination_plugin instanceof MigrationProviderInterface) { + $destination_provider = $destination_plugin->getProvider(); + } + $migration_id = $migration->getPluginId(); + if ($migration_id == 'provider_test') { + $this->assertFalse($source_provider, new FormattableMarkup('Source provider not found for @migration_id.', ['@migration_id' => $migration_id])); + $this->assertFalse($destination_provider, new FormattableMarkup('Destination provider not found for @migration_id.', ['@migration_id' => $migration_id])); + } + elseif ($migration_id == 'provider_no_annotation') { + $this->assertFalse($source_provider, new FormattableMarkup('Source provider not found for @migration_id.', ['@migration_id' => $migration_id])); + $this->assertTrue($destination_provider, new FormattableMarkup('Destination provider found for @migration_id.', ['@migration_id' => $migration_id])); + } + else { + $this->assertTrue($source_provider, new FormattableMarkup('Source provider found for @migration_id.', ['@migration_id' => $migration_id])); + $this->assertTrue($destination_provider, new FormattableMarkup('Destination provider found for @migration_id.', ['@migration_id' => $migration_id])); + } + // Destination provider can't be migrate or migrate_drupal or migrate_drupal_ui + $invalid_destinations = ['migrate', 'migrate_drupal', 'migrate_drupal_ui']; + $this->assertNotContains($destination_provider, $invalid_destinations, new FormattableMarkup('Invalid destination for @migration_id.', ['@migration_id' => $migration_id])); + } + } + +}