5 * Provides migration from other Drupal sites.
8 use Drupal\Core\Database\DatabaseExceptionWrapper;
9 use Drupal\Core\Routing\RouteMatchInterface;
10 use Drupal\migrate\Exception\RequirementsException;
11 use Drupal\migrate\MigrateExecutable;
12 use Drupal\migrate\Plugin\RequirementsInterface;
15 * Implements hook_help().
17 function migrate_drupal_help($route_name, RouteMatchInterface $route_match) {
18 switch ($route_name) {
19 case 'help.page.migrate_drupal':
21 $output .= '<h3>' . t('About') . '</h3>';
22 $output .= '<p>' . t('The Migrate Drupal module provides a framework based on the <a href=":migrate">Migrate module</a> to facilitate migration from a Drupal (6, 7, or 8) site to your website. It does not provide a user interface. For more information, see the <a href=":migrate_drupal">online documentation for the Migrate Drupal module</a>.', [':migrate' => \Drupal::url('help.page', ['name' => 'migrate']), ':migrate_drupal' => 'https://www.drupal.org/documentation/modules/migrate_drupal']) . '</p>';
28 * Implements hook_migration_plugins_alter().
30 function migrate_drupal_migration_plugins_alter(&$definitions) {
31 // This is why the deriver can't do this: the 'd6_taxonomy_vocabulary'
32 // definition is not available to the deriver as it is running inside
34 if (isset($definitions['d6_taxonomy_vocabulary'])) {
35 $vocabulary_migration_definition = [
38 'plugin' => 'd6_taxonomy_vocabulary',
47 $vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($vocabulary_migration_definition);
50 $source_plugin = $vocabulary_migration->getSourcePlugin();
51 if ($source_plugin instanceof RequirementsInterface) {
52 $source_plugin->checkRequirements();
54 $executable = new MigrateExecutable($vocabulary_migration);
55 $process = ['vid' => $definitions['d6_taxonomy_vocabulary']['process']['vid']];
56 foreach ($source_plugin as $row) {
57 $executable->processRow($row, $process);
58 $source_vid = $row->getSourceProperty('vid');
59 $plugin_ids = ['d6_term_node:' . $source_vid, 'd6_term_node_revision:' . $source_vid];
60 foreach ($plugin_ids as $plugin_id) {
61 // Match the field name derivation in d6_vocabulary_field.yml.
62 $field_name = substr('field_' . $row->getDestinationProperty('vid'), 0, 32);
64 // The Forum module is expecting 'taxonomy_forums' as the field name
65 // for the forum nodes. The 'forum_vocabulary' source property is
66 // evaluated in Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary
67 // and is set to true if the vocabulary vid being migrated is the
68 // same as the one in the 'forum_nav_vocabulary' variable on the
70 $destination_vid = $row->getSourceProperty('forum_vocabulary') ? 'taxonomy_forums' : $field_name;
71 $definitions[$plugin_id]['process'][$destination_vid] = 'tid';
75 catch (RequirementsException $e) {
76 // This code currently runs whenever the definitions are being loaded and
77 // if you have a Drupal 7 source site then the requirements will not be
78 // met for the d6_taxonomy_vocabulary migration.
80 catch (DatabaseExceptionWrapper $e) {
81 // When the definitions are loaded it is possible the tables will not