function IdConflictForm::buildForm

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

Overrides MigrateUpgradeFormBase::buildForm

File

core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php, line 28

Class

IdConflictForm
Migrate Upgrade Id Conflict form.

Namespace

Drupal\migrate_drupal_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    // Get all the data needed for this form.
    $migrations = $this->store
        ->get('migrations');
    // If data is missing or this is the wrong step, start over.
    if (!$migrations || $this->store
        ->get('step') != 'idconflict') {
        return $this->restartUpgradeForm();
    }
    $migration_ids = array_keys($migrations);
    // Check if there are conflicts. If none, just skip this form!
    $migrations = $this->migrationPluginManager
        ->createInstances($migration_ids);
    $translated_content_conflicts = $content_conflicts = [];
    $results = (new IdAuditor())->auditMultiple($migrations);
    
    /** @var \Drupal\migrate\Audit\AuditResult $result */
    foreach ($results as $result) {
        $destination = $result->getMigration()
            ->getDestinationPlugin();
        if ($destination instanceof EntityContentBase && $destination->isTranslationDestination()) {
            // Translations are not yet supported by the audit system. For now, we
            // only warn the user to be cautious when migrating translated content.
            // I18n support should be added in https://www.drupal.org/node/2905759.
            $translated_content_conflicts[] = $result;
        }
        elseif (!$result->passed()) {
            $content_conflicts[] = $result;
        }
    }
    if ($content_conflicts || $translated_content_conflicts) {
        $this->messenger()
            ->addWarning($this->t('WARNING: Content may be overwritten on your new site.'));
        $form = parent::buildForm($form, $form_state);
        $form['#title'] = $this->t('Upgrade analysis report');
        if ($content_conflicts) {
            $form = $this->conflictsForm($form, $content_conflicts);
        }
        if ($translated_content_conflicts) {
            $form = $this->i18nWarningForm($form, $translated_content_conflicts);
        }
        return $form;
    }
    else {
        $this->store
            ->set('step', 'review');
        return $this->redirect('migrate_drupal_ui.upgrade_review');
    }
}

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