function ReviewForm::buildForm

Same name in other branches
  1. 9 core/modules/migrate_drupal_ui/src/Form/ReviewForm.php \Drupal\migrate_drupal_ui\Form\ReviewForm::buildForm()
  2. 8.9.x core/modules/migrate_drupal_ui/src/Form/ReviewForm.php \Drupal\migrate_drupal_ui\Form\ReviewForm::buildForm()
  3. 10 core/modules/migrate_drupal_ui/src/Form/ReviewForm.php \Drupal\migrate_drupal_ui\Form\ReviewForm::buildForm()

Overrides MigrateUpgradeFormBase::buildForm

File

core/modules/migrate_drupal_ui/src/Form/ReviewForm.php, line 114

Class

ReviewForm
Migrate Upgrade review form.

Namespace

Drupal\migrate_drupal_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    // Get all the data needed for this form.
    $version = $this->store
        ->get('version');
    $this->migrations = $this->store
        ->get('migrations');
    // Fetch the source system data at the first opportunity.
    $this->systemData = $this->store
        ->get('system_data');
    // If data is missing or this is the wrong step, start over.
    if (!$version || !$this->migrations || !$this->systemData || $this->store
        ->get('step') != 'review') {
        return $this->restartUpgradeForm();
    }
    $form = parent::buildForm($form, $form_state);
    $form['#title'] = $this->t('What will be upgraded?');
    $migrations = $this->migrationPluginManager
        ->createInstances(array_keys($this->store
        ->get('migrations')));
    // Get the upgrade states for the source modules.
    $display = $this->migrationState
        ->getUpgradeStates($version, $this->systemData, $migrations);
    // Missing migrations.
    $missing_module_list = [
        '#type' => 'details',
        '#open' => TRUE,
        '#title' => $this->t('Modules that will not be upgraded'),
        '#summary_attributes' => [
            'id' => [
                'error',
            ],
        ],
        '#description' => $this->t('The new site is missing modules corresponding to the old site\'s modules. Unless they are installed prior to the upgrade, configuration and/or content needed by them will not be available on your new site. <a href=":review">Read the checklist</a> to help decide what to do.', [
            ':review' => 'https://www.drupal.org/docs/upgrading-drupal/upgrading-from-drupal-6-or-drupal-7/upgrade-using-web-browser#pre-upgrade-analysis',
        ]),
        '#weight' => 2,
    ];
    $missing_module_list['module_list'] = [
        '#type' => 'table',
        '#header' => [
            $this->t('Drupal @version module name', [
                '@version' => $version,
            ]),
            $this->t('Drupal @version machine name', [
                '@version' => $version,
            ]),
            $this->t('Drupal @version', [
                '@version' => $this->destinationSiteVersion,
            ]),
        ],
    ];
    $missing_count = 0;
    if (isset($display[MigrationState::NOT_FINISHED])) {
        $output = $this->prepareOutput($display[MigrationState::NOT_FINISHED]);
        foreach ($output as $data) {
            $missing_count++;
            // Get the migration status for each source module, if a module of the
            // same name exists on the destination site.
            $missing_module_list['module_list']['#rows'][] = [
                [
                    'data' => $data['source_module_name'],
                    'class' => [
                        'upgrade-analysis-report__status-icon',
                        'upgrade-analysis-report__status-icon--error',
                    ],
                ],
                $data['source_machine_name'],
                $data['destination'],
            ];
        }
    }
    // Available migrations.
    $available_module_list = [
        '#type' => 'details',
        '#title' => $this->t('Modules that will be upgraded'),
        '#summary_attributes' => [
            'id' => [
                'checked',
            ],
        ],
        '#weight' => 4,
    ];
    $available_module_list['module_list'] = [
        '#type' => 'table',
        '#header' => [
            $this->t('Drupal @version module name', [
                '@version' => $version,
            ]),
            $this->t('Drupal @version machine name', [
                '@version' => $version,
            ]),
            $this->t('Drupal @version', [
                '@version' => $this->destinationSiteVersion,
            ]),
        ],
    ];
    $available_count = 0;
    if (isset($display[MigrationState::FINISHED])) {
        $output = $this->prepareOutput($display[MigrationState::FINISHED]);
        foreach ($output as $data) {
            $available_count++;
            $available_module_list['module_list']['#rows'][] = [
                [
                    'data' => $data['source_module_name'],
                    'class' => [
                        'upgrade-analysis-report__status-icon',
                        'upgrade-analysis-report__status-icon--checked',
                    ],
                ],
                $data['source_machine_name'],
                $data['destination'],
            ];
        }
    }
    $counters = [];
    $general_info = [];
    if ($missing_count) {
        $counters[] = [
            '#theme' => 'status_report_counter',
            '#amount' => $missing_count,
            '#text' => $this->formatPlural($missing_count, 'Module will not be upgraded', 'Modules will not be upgraded'),
            '#severity' => 'error',
            '#weight' => 0,
        ];
        $general_info[] = $missing_module_list;
    }
    if ($available_count) {
        $counters[] = [
            '#theme' => 'status_report_counter',
            '#amount' => $available_count,
            '#text' => $this->formatPlural($available_count, 'Module will be upgraded', 'Modules will be upgraded'),
            '#severity' => 'checked',
            '#weight' => 1,
        ];
        $general_info[] = $available_module_list;
    }
    $form['status_report_page'] = [
        '#theme' => 'status_report_page',
        '#counters' => $counters,
        '#general_info' => $general_info,
    ];
    $form['#attached']['library'][] = 'migrate_drupal_ui/base';
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.