Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_plus.module
1 <?php
2
3 /**
4  * @file
5  * Provides enhancements for implementing and managing migrations.
6  */
7
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate\Plugin\MigrateSourceInterface;
10 use Drupal\migrate\Row;
11 use Drupal\migrate_plus\Entity\MigrationGroup;
12 use Drupal\migrate_plus\Event\MigrateEvents;
13 use Drupal\migrate_plus\Event\MigratePrepareRowEvent;
14
15 /**
16  * Implements hook_migration_plugins_alter().
17  */
18 function migrate_plus_migration_plugins_alter(array &$migrations) {
19   /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
20   foreach ($migrations as $id => $migration) {
21     // Add the default class where empty.
22     if (empty($migration['class'])) {
23       $migrations[$id]['class'] = 'Drupal\migrate\Plugin\Migration';
24     }
25
26     // For derived configuration entity-based migrations, strip the deriver
27     // prefix so we can reference migrations by the IDs they specify (i.e.,
28     // the migration that specifies "id: temp" can be referenced as "temp"
29     // rather than "migration_config_deriver:temp").
30     $prefix = 'migration_config_deriver:';
31     if (strpos($id, $prefix) === 0) {
32       $new_id = substr($id, strlen($prefix));
33       $migrations[$new_id] = $migrations[$id];
34       unset($migrations[$id]);
35       $id = $new_id;
36     }
37
38     // Integrate shared group configuration into the migration.
39     if (empty($migration['migration_group'])) {
40       $migration['migration_group'] = 'default';
41     }
42     $group = MigrationGroup::load($migration['migration_group']);
43     if (empty($group)) {
44       // If the specified group does not exist, create it. Provide a little more
45       // for the 'default' group.
46       $group_properties = [];
47       $group_properties['id'] = $migration['migration_group'];
48       if ($migration['migration_group'] == 'default') {
49         $group_properties['label'] = 'Default';
50         $group_properties['description'] = 'A container for any migrations not explicitly assigned to a group.';
51       }
52       else {
53         $group_properties['label'] = $group_properties['id'];
54         $group_properties['description'] = '';
55       }
56       $group = MigrationGroup::create($group_properties);
57       $group->save();
58     }
59     $shared_configuration = $group->get('shared_configuration');
60     if (empty($shared_configuration)) {
61       continue;
62     }
63     foreach ($shared_configuration as $key => $group_value) {
64       $migration_value = $migration[$key];
65       // Where both the migration and the group provide arrays, replace
66       // recursively (so each key collision is resolved in favor of the
67       // migration).
68       if (is_array($migration_value) && is_array($group_value)) {
69         $merged_values = array_replace_recursive($group_value, $migration_value);
70         $migrations[$id][$key] = $merged_values;
71       }
72       // Where the group provides a value the migration doesn't, use the group
73       // value.
74       elseif (is_null($migration_value)) {
75         $migrations[$id][$key] = $group_value;
76       }
77       // Otherwise, the existing migration value overrides the group value.
78     }
79   }
80 }
81
82 /**
83  * Implements hook_migrate_prepare_row().
84  */
85 function migrate_plus_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
86   \Drupal::service('event_dispatcher')->dispatch(MigrateEvents::PREPARE_ROW, new MigratePrepareRowEvent($row, $source, $migration));
87 }