-
Notifications
You must be signed in to change notification settings - Fork 0
/
paragraphs_migration.module
109 lines (101 loc) · 3.89 KB
/
paragraphs_migration.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @file
* Contains paragraphs_migration.module.
*/
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\paragraphs_migration\MigrationPluginsAlterer;
use Drupal\paragraphs_migration\Plugin\migrate\ParagraphsCallback;
use Drupal\paragraphs_migration\Utility\MultifieldMigration;
/**
* Implements hook_migration_plugins_alter().
*
* @todo refactor/rethink this when
* https://www.drupal.org/project/drupal/issues/2904765 is resolved
*/
function paragraphs_migration_migration_plugins_alter(array &$migrations) {
foreach ($migrations as $key => &$value) {
$migrations[$key]['idMap'] = ['plugin' => 'smart_sql'];
if ($value['provider'] === 'paragraphs') {
unset($migrations[$key]);
}
}
$migration_plugins_alterer = \Drupal::service('paragraphs_migration.migration_plugins_alterer');
assert($migration_plugins_alterer instanceof MigrationPluginsAlterer);
$migration_plugins_alterer->alterMigrationPlugins($migrations);
}
/**
* Implements hook_migrate_process_info_alter().
*/
function paragraphs_migration_migrate_process_info_alter(&$definitions) {
// Adds the improved version of 'callback' process plugin from Drupal core
// 9.2.0+. That version comes with a new option that makes us able to use the
// return value of functions with multiple arguments, meaning that we can
// remove the 'field_' prefix of field collection source 'bundles'.
// @see https://www.drupal.org/node/3205079
if (
(
version_compare(\Drupal::VERSION, '9.2.0', 'lt') &&
\Drupal::VERSION !== '9.2.x-dev'
) &&
!empty($definitions['callback'])
) {
$definitions['paragraphs_callback'] = $definitions['callback'];
$definitions['paragraphs_callback']['class'] = ParagraphsCallback::class;
$definitions['paragraphs_callback']['provider'] = 'paragraphs';
}
}
/**
* Implements hook_query_alter().
*/
function paragraphs_migration_query_migrate_field_value_alter(AlterableInterface $query) {
if (!$query instanceof SelectInterface) {
return;
}
// Requires core patch at https://drupal.org/i/3218294
MultifieldMigration::addCruicalMultifieldFieldProperties($query);
}
/**
* Alter the registry of modules implementing a hook.
*
* This hook is invoked during \Drupal::moduleHandler()->getImplementations().
* A module may implement this hook in order to reorder the implementing
* modules, which are otherwise ordered by the module's system weight.
*
* Note that hooks invoked using \Drupal::moduleHandler->alter() can have
* multiple variations(such as hook_form_alter() and hook_form_FORM_ID_alter()).
* \Drupal::moduleHandler->alter() will call all such variants defined by a
* single module in turn. For the purposes of hook_module_implements_alter(),
* these variants are treated as a single hook. Thus, to ensure that your
* implementation of hook_form_FORM_ID_alter() is called at the right time,
* you will have to change the order of hook_form_alter() implementation in
* hook_module_implements_alter().
*
* @param array $implementations
* An array keyed by the module's name. The value of each item corresponds
* to a $group, which is usually FALSE, unless the implementation is in a
* file named $module.$group.inc.
* @param string $hook
* The name of the module hook being implemented.
*/
function paragraphs_migration_module_implements_alter(array &$implementations, string $hook) {
$migration_hooks = [
'migration_plugins_alter',
'migrate_field_info_alter',
];
if (in_array($hook, $migration_hooks, TRUE)) {
// Remove every paragraphs hook implementations.
unset($implementations['paragraphs']);
}
}
/**
* Implements hook_migrate_field_info_alter().
*/
function paragraphs_migration_migrate_field_info_alter(&$definitions) {
foreach ($definitions as $definition) {
if ($definition['provider'] === 'paragraphs') {
unset($definitions[$definition['id']]);
}
}
}