diff --git a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php index f17768ef3b2e827fad586c4d45120ca1512d0082..8cb60347bc01ec7dcc47b002b49c043f1577e743 100644 --- a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php +++ b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php @@ -13,6 +13,27 @@ */ trait MigrationConfigurationTrait { + /** + * The config factory service. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + + /** + * The migration plugin manager service. + * + * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface + */ + protected $migrationPluginManager; + + /** + * The state service. + * + * @var \Drupal\Core\State\StateInterface + */ + protected $state; + /** * The follow-up migration tags. * @@ -82,8 +103,9 @@ protected function createDatabaseStateSettings(array $database, $drupal_version) $database_state['key'] = 'upgrade'; $database_state['database'] = $database; $database_state_key = 'migrate_drupal_' . $drupal_version; - \Drupal::state()->set($database_state_key, $database_state); - \Drupal::state()->set('migrate.fallback_state_key', $database_state_key); + $state = $this->getState(); + $state->set($database_state_key, $database_state); + $state->set('migrate.fallback_state_key', $database_state_key); } /** @@ -99,9 +121,8 @@ protected function createDatabaseStateSettings(array $database, $drupal_version) */ protected function getMigrations($database_state_key, $drupal_version) { $version_tag = 'Drupal ' . $drupal_version; - $plugin_manager = \Drupal::service('plugin.manager.migration'); /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */ - $all_migrations = $plugin_manager->createInstancesByTag($version_tag); + $all_migrations = $this->getMigrationPluginManager()->createInstancesByTag($version_tag); $migrations = []; foreach ($all_migrations as $migration) { // Skip migrations tagged with any of the follow-up migration tags. They @@ -147,7 +168,7 @@ protected function getMigrations($database_state_key, $drupal_version) { */ protected function getFollowUpMigrationTags() { if ($this->followUpMigrationTags === NULL) { - $this->followUpMigrationTags = \Drupal::configFactory() + $this->followUpMigrationTags = $this->getConfigFactory() ->get('migrate_drupal.settings') ->get('follow_up_migration_tags') ?: []; } @@ -210,4 +231,46 @@ protected function getLegacyDrupalVersion(Connection $connection) { return $version_string ? substr($version_string, 0, 1) : FALSE; } + /** + * Gets the config factory service. + * + * @return \Drupal\Core\Config\ConfigFactoryInterface + * The config factory service. + */ + protected function getConfigFactory() { + if (!$this->configFactory) { + $this->configFactory = \Drupal::service('config.factory'); + } + + return $this->configFactory; + } + + /** + * Gets the migration plugin manager service. + * + * @return \Drupal\migrate\Plugin\MigrationPluginManagerInterface + * The migration plugin manager service. + */ + protected function getMigrationPluginManager() { + if (!$this->migrationPluginManager) { + $this->migrationPluginManager = \Drupal::service('plugin.manager.migration'); + } + + return $this->migrationPluginManager; + } + + /** + * Gets the state service. + * + * @return \Drupal\Core\State\StateInterface + * The state service. + */ + protected function getState() { + if (!$this->state) { + $this->state = \Drupal::service('state'); + } + + return $this->state; + } + } diff --git a/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php b/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php index 7a4ca439d628d9f09e4059db012c6b9ccb18b4d6..3443db867c8c6865f6dabccdb2e980bb258c9991 100644 --- a/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php @@ -3,11 +3,14 @@ namespace Drupal\migrate_drupal_ui\Form; use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\State\StateInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException; +use Drupal\migrate\Plugin\MigrationPluginManagerInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\TransferException; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -37,12 +40,18 @@ class CredentialForm extends MigrateUpgradeFormBase { * CredentialForm constructor. * * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private - * The private tempstore factory. + * The private tempstore factory service. * @param \GuzzleHttp\ClientInterface $http_client * A Guzzle client object. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager + * The migration plugin manager service. + * @param \Drupal\Core\State\StateInterface $state + * The state service. */ - public function __construct(PrivateTempStoreFactory $tempstore_private, ClientInterface $http_client) { - parent::__construct($tempstore_private); + public function __construct(PrivateTempStoreFactory $tempstore_private, ClientInterface $http_client, ConfigFactoryInterface $config_factory, MigrationPluginManagerInterface $migration_plugin_manager, StateInterface $state) { + parent::__construct($config_factory, $migration_plugin_manager, $state, $tempstore_private); $this->httpClient = $http_client; } @@ -52,7 +61,10 @@ public function __construct(PrivateTempStoreFactory $tempstore_private, ClientIn public static function create(ContainerInterface $container) { return new static( $container->get('tempstore.private'), - $container->get('http_client') + $container->get('http_client'), + $container->get('config.factory'), + $container->get('plugin.manager.migration'), + $container->get('state') ); } diff --git a/core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php b/core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php index 2492143abc29b4716e4c4f5c2008e0a0681bedc6..ec58b940812b69bff551f44558d3022c914c8df4 100644 --- a/core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php @@ -3,11 +3,8 @@ namespace Drupal\migrate_drupal_ui\Form; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\migrate\Audit\IdAuditor; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; -use Drupal\migrate\Plugin\MigrationPluginManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Migrate Upgrade Id Conflict form. @@ -16,36 +13,6 @@ */ class IdConflictForm extends MigrateUpgradeFormBase { - /** - * The migration plugin manager service. - * - * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface - */ - protected $pluginManager; - - /** - * IdConflictForm constructor. - * - * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager - * The migration plugin manager service. - * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private - * The private tempstore factory. - */ - public function __construct(MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private) { - parent::__construct($tempstore_private); - $this->pluginManager = $migration_plugin_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.migration'), - $container->get('tempstore.private') - ); - } - /** * {@inheritdoc} */ @@ -67,7 +34,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $migration_ids = array_keys($migrations); // Check if there are conflicts. If none, just skip this form! - $migrations = $this->pluginManager->createInstances($migration_ids); + $migrations = $this->migrationPluginManager->createInstances($migration_ids); $translated_content_conflicts = $content_conflicts = []; diff --git a/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php b/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php index 617514f1e87ebc343adde2ad15a2d63d478e5de0..3807a280d17ed4a4355a2e0c95932619c4367383 100644 --- a/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php @@ -2,10 +2,12 @@ namespace Drupal\migrate_drupal_ui\Form; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; +use Drupal\migrate\Plugin\MigrationPluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -15,13 +17,6 @@ */ class IncrementalForm extends MigrateUpgradeFormBase { - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - /** * The date formatter service. * @@ -37,11 +32,14 @@ class IncrementalForm extends MigrateUpgradeFormBase { * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter service. * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private - * The private temp store factory. + * The private tempstore factory service. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager + * The migration plugin manager service. */ - public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, PrivateTempStoreFactory $tempstore_private) { - parent::__construct($tempstore_private); - $this->state = $state; + public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, PrivateTempStoreFactory $tempstore_private, ConfigFactoryInterface $config_factory, MigrationPluginManagerInterface $migration_plugin_manager) { + parent::__construct($config_factory, $migration_plugin_manager, $state, $tempstore_private); $this->dateFormatter = $date_formatter; } @@ -52,7 +50,9 @@ public static function create(ContainerInterface $container) { return new static( $container->get('state'), $container->get('date.formatter'), - $container->get('tempstore.private') + $container->get('tempstore.private'), + $container->get('config.factory'), + $container->get('plugin.manager.migration') ); } diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeFormBase.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeFormBase.php index 92021457bf80956bcd5f9bdd1b91892a8a46d119..193620dfcd3d6c7ff53369b3a9fc138f647cc75d 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeFormBase.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeFormBase.php @@ -2,10 +2,13 @@ namespace Drupal\migrate_drupal_ui\Form; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\migrate_drupal\MigrationConfigurationTrait; +use Drupal\Core\State\StateInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; +use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate_drupal\MigrationConfigurationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -25,10 +28,19 @@ abstract class MigrateUpgradeFormBase extends FormBase { /** * Constructs the Migrate Upgrade Form Base. * + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager + * The migration plugin manager service. + * @param \Drupal\Core\State\StateInterface $state + * The state service. * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private - * Private store. + * The private tempstore factory service. */ - public function __construct(PrivateTempStoreFactory $tempstore_private) { + public function __construct(ConfigFactoryInterface $config_factory, MigrationPluginManagerInterface $migration_plugin_manager, StateInterface $state, PrivateTempStoreFactory $tempstore_private) { + $this->configFactory = $config_factory; + $this->migrationPluginManager = $migration_plugin_manager; + $this->state = $state; $this->store = $tempstore_private->get('migrate_drupal_ui'); } @@ -37,6 +49,9 @@ public function __construct(PrivateTempStoreFactory $tempstore_private) { */ public static function create(ContainerInterface $container) { return new static( + $container->get('config.factory'), + $container->get('plugin.manager.migration'), + $container->get('state'), $container->get('tempstore.private') ); } diff --git a/core/modules/migrate_drupal_ui/src/Form/OverviewForm.php b/core/modules/migrate_drupal_ui/src/Form/OverviewForm.php index 22b45a9104381d8d3a4b3d4ae5e36f031665fd16..91c9fb2ab410c91b8b03f93c16c014d2c6154db8 100644 --- a/core/modules/migrate_drupal_ui/src/Form/OverviewForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/OverviewForm.php @@ -3,10 +3,7 @@ namespace Drupal\migrate_drupal_ui\Form; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\State\StateInterface; -use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\Core\Url; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Migrate Upgrade Overview form. @@ -15,36 +12,6 @@ */ class OverviewForm extends MigrateUpgradeFormBase { - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * Overview form constructor. - * - * @param \Drupal\Core\State\StateInterface $state - * The state service. - * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private - * The private tempstore factory. - */ - public function __construct(StateInterface $state, PrivateTempStoreFactory $tempstore_private) { - parent::__construct($tempstore_private); - $this->state = $state; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('state'), - $container->get('tempstore.private') - ); - } - /** * {@inheritdoc} */ diff --git a/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php index 314eeff6b979245d2016dc8e19a2a82f74a8258a..5be85c42f213424cf1527a42c9f36065704445f9 100644 --- a/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/ReviewForm.php @@ -2,13 +2,13 @@ namespace Drupal\migrate_drupal_ui\Form; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; -use Drupal\migrate\Plugin\MigrationPluginManagerInterface; -use Drupal\migrate_drupal\MigrationState; -use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface; use Drupal\migrate_drupal_ui\Batch\MigrateUpgradeImportBatch; +use Drupal\migrate_drupal\MigrationState; +use Drupal\migrate\Plugin\MigrationPluginManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -30,27 +30,6 @@ */ class ReviewForm extends MigrateUpgradeFormBase { - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * The migration plugin manager service. - * - * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface - */ - protected $pluginManager; - - /** - * The field plugin manager service. - * - * @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface - */ - protected $fieldPluginManager; - /** * The migrations. * @@ -72,18 +51,15 @@ class ReviewForm extends MigrateUpgradeFormBase { * The state service. * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager * The migration plugin manager service. - * @param \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface $field_plugin_manager - * The field plugin manager service. * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private - * The private tempstore factory. + * The private tempstore factory service. * @param \Drupal\migrate_drupal\MigrationState $migrationState * Migration state service. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. */ - public function __construct(StateInterface $state, MigrationPluginManagerInterface $migration_plugin_manager, MigrateFieldPluginManagerInterface $field_plugin_manager, PrivateTempStoreFactory $tempstore_private, MigrationState $migrationState) { - parent::__construct($tempstore_private); - $this->state = $state; - $this->pluginManager = $migration_plugin_manager; - $this->fieldPluginManager = $field_plugin_manager; + public function __construct(StateInterface $state, MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private, MigrationState $migrationState, ConfigFactoryInterface $config_factory) { + parent::__construct($config_factory, $migration_plugin_manager, $state, $tempstore_private); $this->migrationState = $migrationState; } @@ -94,9 +70,9 @@ public static function create(ContainerInterface $container) { return new static( $container->get('state'), $container->get('plugin.manager.migration'), - $container->get('plugin.manager.migrate.field'), $container->get('tempstore.private'), - $container->get('migrate_drupal.migration_state') + $container->get('migrate_drupal.migration_state'), + $container->get('config.factory') ); } @@ -126,7 +102,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $form['#title'] = $this->t('What will be upgraded?'); - $migrations = $this->pluginManager->createInstances(array_keys($this->store->get('migrations'))); + $migrations = $this->migrationPluginManager->createInstances(array_keys($this->store->get('migrations'))); // Get the upgrade states for the source modules. $display = $this->migrationState->getUpgradeStates($version, $system_data, $migrations);