class IdConflictForm

Same name in other branches
  1. 8.9.x core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php \Drupal\migrate_drupal_ui\Form\IdConflictForm
  2. 10 core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php \Drupal\migrate_drupal_ui\Form\IdConflictForm
  3. 11.x core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php \Drupal\migrate_drupal_ui\Form\IdConflictForm

Migrate Upgrade Id Conflict form.

@internal

Hierarchy

Expanded class hierarchy of IdConflictForm

1 string reference to 'IdConflictForm'
migrate_drupal_ui.routing.yml in core/modules/migrate_drupal_ui/migrate_drupal_ui.routing.yml
core/modules/migrate_drupal_ui/migrate_drupal_ui.routing.yml

File

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

Namespace

Drupal\migrate_drupal_ui\Form
View source
class IdConflictForm extends MigrateUpgradeFormBase {
    
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'migrate_drupal_ui_idconflict_form';
    }
    
    /**
     * {@inheritdoc}
     */
    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');
        }
    }
    
    /**
     * Build the markup for conflict warnings.
     *
     * @param array $form
     *   An associative array containing the structure of the form.
     * @param \Drupal\migrate\Audit\AuditResult[] $conflicts
     *   The failing audit results.
     *
     * @return array
     *   The form structure.
     */
    protected function conflictsForm(array &$form, array $conflicts) {
        $form['conflicts'] = [
            '#title' => $this->t('There is conflicting content of these types:'),
            '#theme' => 'item_list',
            '#items' => $this->formatConflicts($conflicts),
        ];
        $form['warning'] = [
            '#type' => 'markup',
            '#markup' => '<p>' . $this->t('It looks like you have content on your new site which <strong>may be overwritten</strong> if you continue to run this upgrade. The upgrade should be performed on a clean Drupal @version installation. For more information see the <a target="_blank" href=":id-conflicts-handbook">upgrade handbook</a>.', [
                '@version' => $this->destinationSiteVersion,
                ':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts',
            ]) . '</p>',
        ];
        return $form;
    }
    
    /**
     * Formats a set of failing audit results as strings.
     *
     * Each string is the label of the destination plugin of the migration that
     * failed the audit, keyed by the destination plugin ID in order to prevent
     * duplication.
     *
     * @param \Drupal\migrate\Audit\AuditResult[] $conflicts
     *   The failing audit results.
     *
     * @return string[]
     *   The formatted audit results.
     */
    protected function formatConflicts(array $conflicts) {
        $items = [];
        foreach ($conflicts as $conflict) {
            $definition = $conflict->getMigration()
                ->getDestinationPlugin()
                ->getPluginDefinition();
            $id = $definition['id'];
            $items[$id] = $definition['label'];
        }
        sort($items, SORT_STRING);
        return array_unique($items);
    }
    
    /**
     * Build the markup for i18n warnings.
     *
     * @param array $form
     *   An associative array containing the structure of the form.
     * @param \Drupal\migrate\Audit\AuditResult[] $conflicts
     *   The failing audit results.
     *
     * @return array
     *   The form structure.
     */
    protected function i18nWarningForm(array &$form, array $conflicts) {
        $form['i18n'] = [
            '#title' => $this->t('There is translated content of these types:'),
            '#theme' => 'item_list',
            '#items' => $this->formatConflicts($conflicts),
        ];
        $form['i18n_warning'] = [
            '#type' => 'markup',
            '#markup' => '<p>' . $this->t('It looks like you are migrating translated content from your old site. Possible ID conflicts for translations are not automatically detected in the current version of Drupal. Refer to the <a target="_blank" href=":id-conflicts-handbook">upgrade handbook</a> for instructions on how to avoid ID conflicts with translated content.', [
                ':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts',
            ]) . '</p>',
        ];
        return $form;
    }
    
    /**
     * {@inheritdoc}
     */
    public function submitForm(array &$form, FormStateInterface $form_state) {
        $this->store
            ->set('step', 'review');
        $form_state->setRedirect('migrate_drupal_ui.upgrade_review');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getConfirmText() {
        return $this->t('I acknowledge I may lose data. Continue anyway.');
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 73
IdConflictForm::buildForm public function Form constructor. Overrides MigrateUpgradeFormBase::buildForm
IdConflictForm::conflictsForm protected function Build the markup for conflict warnings.
IdConflictForm::formatConflicts protected function Formats a set of failing audit results as strings.
IdConflictForm::getConfirmText public function Returns a caption for the button that confirms the action. Overrides MigrateUpgradeFormBase::getConfirmText
IdConflictForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
IdConflictForm::i18nWarningForm protected function Build the markup for i18n warnings.
IdConflictForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 17
MessengerTrait::messenger public function Gets the messenger. 17
MessengerTrait::setMessenger public function Sets the messenger.
MigrateUpgradeFormBase::$destinationSiteVersion protected property The destination site major version.
MigrateUpgradeFormBase::$store protected property Private temporary storage.
MigrateUpgradeFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 3
MigrateUpgradeFormBase::restartUpgradeForm protected function Helper to redirect to the Overview form.
MigrateUpgradeFormBase::__construct public function Constructs the Migrate Upgrade Form Base. 3
MigrationConfigurationTrait::$configFactory protected property The config factory service.
MigrationConfigurationTrait::$followUpMigrationTags protected property The follow-up migration tags.
MigrationConfigurationTrait::$migrationPluginManager protected property The migration plugin manager service.
MigrationConfigurationTrait::$state protected property The state service.
MigrationConfigurationTrait::createDatabaseStateSettings protected function Creates the necessary state entries for SqlBase::getDatabase() to work.
MigrationConfigurationTrait::getConfigFactory protected function Gets the config factory service.
MigrationConfigurationTrait::getConnection protected function Gets the database connection for the source Drupal database.
MigrationConfigurationTrait::getFollowUpMigrationTags protected function Returns the follow-up migration tags.
MigrationConfigurationTrait::getLegacyDrupalVersion public static function Determines what version of Drupal the source database contains.
MigrationConfigurationTrait::getMigrationPluginManager protected function Gets the migration plugin manager service.
MigrationConfigurationTrait::getMigrations protected function Gets the migrations for import.
MigrationConfigurationTrait::getState protected function Gets the state service.
MigrationConfigurationTrait::getSystemData protected function Gets the system data from the system table of the source Drupal database.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a &#039;destination&#039; URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

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