IdConflictForm.php in Drupal 10
File
core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php
View source
<?php
namespace Drupal\migrate_drupal_ui\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\migrate\Audit\IdAuditor;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
class IdConflictForm extends MigrateUpgradeFormBase {
public function getFormId() {
return 'migrate_drupal_ui_idconflict_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$migrations = $this->store
->get('migrations');
if (!$migrations || $this->store
->get('step') != 'idconflict') {
return $this
->restartUpgradeForm();
}
$migration_ids = array_keys($migrations);
$migrations = $this->migrationPluginManager
->createInstances($migration_ids);
$translated_content_conflicts = $content_conflicts = [];
$results = (new IdAuditor())
->auditMultiple($migrations);
foreach ($results as $result) {
$destination = $result
->getMigration()
->getDestinationPlugin();
if ($destination instanceof EntityContentBase && $destination
->isTranslationDestination()) {
$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');
}
}
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;
}
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);
}
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;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->store
->set('step', 'review');
$form_state
->setRedirect('migrate_drupal_ui.upgrade_review');
}
public function getConfirmText() {
return $this
->t('I acknowledge I may lose data. Continue anyway.');
}
}