3 namespace Drupal\migrate_drupal_ui\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\migrate_drupal\MigrationConfigurationTrait;
8 use Drupal\Core\TempStore\PrivateTempStoreFactory;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Form base for the Migrate Upgrade UI.
14 abstract class MigrateUpgradeFormBase extends FormBase {
16 use MigrationConfigurationTrait;
19 * Private temporary storage.
21 * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
26 * Constructs the Migrate Upgrade Form Base.
28 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private
31 public function __construct(PrivateTempStoreFactory $tempstore_private) {
32 $this->store = $tempstore_private->get('migrate_drupal_ui');
38 public static function create(ContainerInterface $container) {
40 $container->get('tempstore.private')
47 public function buildForm(array $form, FormStateInterface $form_state) {
49 $form['actions']['#type'] = 'actions';
50 $form['actions']['submit'] = [
52 '#value' => $this->getConfirmText(),
53 '#button_type' => 'primary',
60 * Gets and stores information for this migration in temporary store.
62 * Gets all the migrations, converts each to an array and stores it in the
63 * form state. The source base path for public and private files is also
64 * put into form state.
66 * @param array $database
67 * Database array representing the source Drupal database.
68 * @param \Drupal\Core\Form\FormStateInterface $form_state
69 * The current state of the form.
71 protected function setupMigrations(array $database, FormStateInterface $form_state) {
72 $connection = $this->getConnection($database);
73 $version = $this->getLegacyDrupalVersion($connection);
74 $this->createDatabaseStateSettings($database, $version);
75 $migrations = $this->getMigrations('migrate_drupal_' . $version, $version);
77 // Get the system data from source database.
78 $system_data = $this->getSystemData($connection);
80 // Convert the migration object into array
81 // so that it can be stored in form storage.
82 $migration_array = [];
83 foreach ($migrations as $migration) {
84 $migration_array[$migration->id()] = $migration->label();
87 // Store information in the private store.
88 $this->store->set('version', $version);
89 $this->store->set('migrations', $migration_array);
91 $this->store->set('source_base_path', $form_state->getValue('d6_source_base_path'));
94 $this->store->set('source_base_path', $form_state->getValue('source_base_path'));
96 $this->store->set('source_private_file_path', $form_state->getValue('source_private_file_path'));
97 // Store the retrieved system data in the private store.
98 $this->store->set('system_data', $system_data);
102 * Helper to redirect to the Overview form.
104 * @return \Symfony\Component\HttpFoundation\RedirectResponse
105 * A redirect response object that may be returned by the controller.
107 protected function restartUpgradeForm() {
108 $this->store->set('step', 'overview');
109 return $this->redirect('migrate_drupal_ui.upgrade');
113 * Returns a caption for the button that confirms the action.
116 * The form confirmation text.
118 abstract protected function getConfirmText();