You are here

public function MigrateUpgradeForm::buildConfirmForm in Migrate Upgrade 8

Confirmation form for rollbacks, missing migrations, etc.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

1 call to MigrateUpgradeForm::buildConfirmForm()
MigrateUpgradeForm::buildForm in src/Form/MigrateUpgradeForm.php
Form constructor.

File

src/Form/MigrateUpgradeForm.php, line 1015
Contains \Drupal\migrate_upgrade\Form\MigrateUpgradeForm.

Class

MigrateUpgradeForm
Defines a multi-step form for performing direct site upgrades.

Namespace

Drupal\migrate_upgrade\Form

Code

public function buildConfirmForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $form['actions']['submit']['#submit'] = [
    '::submitConfirmForm',
  ];
  if ($rollback = $form_state
    ->getValue('upgrade_option') == static::MIGRATE_UPGRADE_ROLLBACK) {
    $form_state
      ->setStorage([
      'upgrade_option' => static::MIGRATE_UPGRADE_ROLLBACK,
    ]);
    $form['rollback'] = [
      '#markup' => $this
        ->t('All previously-imported content, as well as configuration such as field definitions, will be removed.'),
    ];
    $form['actions']['submit']['#value'] = $this
      ->t('Perform rollback');
  }
  else {
    $form['actions']['submit']['#value'] = $this
      ->t('Perform upgrade');
    $table_data = [];
    $system_data = [];
    foreach ($form_state
      ->get('migration') as $migration) {
      $migration_id = $migration['id'];

      // Fetch the system data at the first opportunity.
      if (empty($system_data)) {
        $system_data = $form_state
          ->get('system_data');
      }
      $template_id = $migration['template'];
      $source_module = $this->moduleUpgradePaths[$template_id]['source_module'];
      $destination_module = $this->moduleUpgradePaths[$template_id]['destination_module'];
      $table_data[$source_module][$destination_module][$migration_id] = $migration['label'];
    }
    ksort($table_data);
    foreach ($table_data as $source_module => $destination_module_info) {
      ksort($table_data[$source_module]);
    }
    $unmigrated_source_modules = array_diff_key($system_data['module'], $table_data);

    // Missing migrations.
    $form['missing_module_list_title'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('Missing upgrade paths'),
      '#description' => $this
        ->t('The following items will not be upgraded. For more information see <a href="https://www.drupal.org/upgrade/migrate"> Upgrading from Drupal 6 or 7 to Drupal 8</a>.'),
    ];
    $form['missing_module_list'] = [
      '#type' => 'table',
      '#header' => [
        $this
          ->t('Source'),
        $this
          ->t('Destination'),
      ],
    ];
    $missing_count = 0;
    ksort($unmigrated_source_modules);
    foreach ($unmigrated_source_modules as $source_module => $module_data) {
      if ($module_data['status']) {
        $missing_count++;
        $form['missing_module_list'][$source_module] = [
          'source_module' => [
            '#plain_text' => $source_module,
          ],
          'destination_module' => [
            '#plain_text' => 'Missing',
          ],
        ];
      }
    }

    // Available migrations.
    $form['available_module_list'] = [
      '#tree' => TRUE,
      '#type' => 'details',
      '#title' => $this
        ->t('Available upgrade paths'),
    ];
    $form['available_module_list']['module_list'] = [
      '#type' => 'table',
      '#header' => [
        $this
          ->t('Source'),
        $this
          ->t('Destination'),
      ],
    ];
    $available_count = 0;
    foreach ($table_data as $source_module => $destination_module_info) {
      $available_count++;
      $destination_details = [];
      foreach ($destination_module_info as $destination_module => $migration_ids) {
        $destination_details[$destination_module] = [
          '#type' => 'item',
          '#plain_text' => $destination_module,
        ];
      }
      $form['available_module_list']['module_list'][$source_module] = [
        'source_module' => [
          '#plain_text' => $source_module,
        ],
        'destination_module' => $destination_details,
      ];
    }
    $form['counts'] = [
      '#type' => 'item',
      '#title' => '<ul><li>' . $this
        ->t('@count available upgrade paths', [
        '@count' => $available_count,
      ]) . '</li><li>' . $this
        ->t('@count missing upgrade paths', [
        '@count' => $missing_count,
      ]) . '</li></ul>',
      '#weight' => -15,
    ];
  }
  return $form;
}