class IdConflictForm in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate_drupal_ui/src/Form/IdConflictForm.php \Drupal\migrate_drupal_ui\Form\IdConflictForm
Migrate Upgrade Id Conflict form.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\migrate_drupal_ui\Form\MigrateUpgradeFormBase uses MigrationConfigurationTrait
- class \Drupal\migrate_drupal_ui\Form\IdConflictForm
- class \Drupal\migrate_drupal_ui\Form\MigrateUpgradeFormBase uses MigrationConfigurationTrait
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\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
IdConflictForm:: |
public | function |
Form constructor. Overrides MigrateUpgradeFormBase:: |
|
IdConflictForm:: |
protected | function | Build the markup for conflict warnings. | |
IdConflictForm:: |
protected | function | Formats a set of failing audit results as strings. | |
IdConflictForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides MigrateUpgradeFormBase:: |
|
IdConflictForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
IdConflictForm:: |
protected | function | Build the markup for i18n warnings. | |
IdConflictForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
MigrateUpgradeFormBase:: |
protected | property | The destination site major version. | |
MigrateUpgradeFormBase:: |
protected | property | Private temporary storage. | |
MigrateUpgradeFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
MigrateUpgradeFormBase:: |
protected | function | Helper to redirect to the Overview form. | |
MigrateUpgradeFormBase:: |
public | function | Constructs the Migrate Upgrade Form Base. | |
MigrationConfigurationTrait:: |
protected | property | The config factory service. | |
MigrationConfigurationTrait:: |
protected | property | The follow-up migration tags. | |
MigrationConfigurationTrait:: |
protected | property | The migration plugin manager service. | |
MigrationConfigurationTrait:: |
protected | property | The state service. | |
MigrationConfigurationTrait:: |
protected | function | Creates the necessary state entries for SqlBase::getDatabase() to work. | |
MigrationConfigurationTrait:: |
protected | function | Gets the config factory service. | |
MigrationConfigurationTrait:: |
protected | function | Gets the database connection for the source Drupal database. | |
MigrationConfigurationTrait:: |
protected | function | Returns the follow-up migration tags. | |
MigrationConfigurationTrait:: |
public static | function | Determines what version of Drupal the source database contains. | |
MigrationConfigurationTrait:: |
protected | function | Gets the migration plugin manager service. | |
MigrationConfigurationTrait:: |
protected | function | Gets the migrations for import. | |
MigrationConfigurationTrait:: |
protected | function | Gets the state service. | |
MigrationConfigurationTrait:: |
protected | function | Gets the system data from the system table of the source Drupal database. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |