5 * Hooks provided by the Migrate module.
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate\Plugin\MigrateSourceInterface;
10 use Drupal\migrate\Row;
13 * @defgroup migration Migration API
15 * Overview of the Migration API, which migrates data into Drupal.
17 * @section overview Overview of migration
19 * @link http://wikipedia.org/wiki/Extract,_transform,_load Extract, Transform, Load @endlink
20 * (ETL) process. In the Drupal migration API the extract phase is called
21 * "source", the transform phase is called "process", and the load phase is
22 * called "destination". It is important to understand that the "load" in ETL
23 * means to load data into storage, while traditionally Drupal uses "load" to
24 * mean load data from storage into memory.
26 * In the source phase, a set of data, called the row, is retrieved from the
27 * data source, typically a database but it can be a CSV, JSON or XML file. The
28 * row is sent to the process phase where it is transformed as needed by the
29 * destination, or marked to be skipped. Processing can also determine that a
30 * stub needs to be created, for example, if a term has a parent term that does
31 * not yet exist. After processing the transformed row is passed to the
32 * destination phase where it is loaded (saved) into the Drupal 8 site.
34 * The ETL process is configured by the migration plugin. The different phases:
35 * source, process, and destination are also plugins, and are managed by the
36 * Migration plugin. So there are four types of plugins in the migration
37 * process: migration, source, process and destination.
39 * @section sec_migrations Migration plugins
40 * Migration plugin definitions are stored in a module's 'migrations' directory.
41 * For backwards compatibility we also scan the 'migration_templates' directory.
42 * Examples of migration plugin definitions can be found in
43 * 'core/modules/action/migration_templates'. The plugin class is
44 * \Drupal\migrate\Plugin\Migration, with interface
45 * \Drupal\migrate\Plugin\MigrationInterface. Migration plugins are managed by
46 * the \Drupal\migrate\Plugin\MigrationPluginManager class. Migration plugins
47 * are only available if the providers of their source plugins are installed.
49 * @section sec_source Source plugins
50 * Migration source plugins implement
51 * \Drupal\migrate\Plugin\MigrateSourceInterface and usually extend
52 * \Drupal\migrate\Plugin\migrate\source\SourcePluginBase. They are annotated
53 * with \Drupal\migrate\Annotation\MigrateSource annotation, and must be in
54 * namespace subdirectory Plugin\migrate\source under the namespace of the
55 * module that defines them. Migration source plugins are managed by the
56 * \Drupal\migrate\Plugin\MigrateSourcePluginManager class. Source plugin
57 * providers are determined by their and their parents namespaces.
59 * @section sec_process Process plugins
60 * Migration process plugins implement
61 * \Drupal\migrate\Plugin\MigrateProcessInterface and usually extend
62 * \Drupal\migrate\ProcessPluginBase. They are annotated
63 * with \Drupal\migrate\Annotation\MigrateProcessPlugin annotation, and must be
64 * in namespace subdirectory Plugin\migrate\process under the namespace of the
65 * module that defines them. Migration process plugins are managed by the
66 * \Drupal\migrate\Plugin\MigratePluginManager class. The Migrate module
67 * provides process plugins for common operations (setting default values,
68 * mapping values, etc.).
70 * @section sec_destination Destination plugins
71 * Migration destination plugins implement
72 * \Drupal\migrate\Plugin\MigrateDestinationInterface and usually extend
73 * \Drupal\migrate\Plugin\migrate\destination\DestinationBase. They are
74 * annotated with \Drupal\migrate\Annotation\MigrateDestination annotation, and
75 * must be in namespace subdirectory Plugin\migrate\destination under the
76 * namespace of the module that defines them. Migration destination plugins
77 * are managed by the \Drupal\migrate\Plugin\MigrateDestinationPluginManager
78 * class. The Migrate module provides destination plugins for Drupal core
79 * objects (configuration and entity).
81 * @section sec_more_info More information
82 * @link https://www.drupal.org/node/2127611 Migration API documentation. @endlink
94 * Allows adding data to a row before processing it.
96 * For example, filter module used to store filter format settings in the
97 * variables table which now needs to be inside the filter format config
98 * file. So, it needs to be added here.
100 * hook_migrate_MIGRATION_ID_prepare_row() is also available.
104 function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
105 if ($migration->id() == 'd6_filter_formats') {
106 $value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', [':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')])->fetchField();
108 $row->setSourceProperty('settings:mymodule:foo', unserialize($value));
114 * Allows altering the list of discovered migration plugins.
116 * Modules are able to alter specific migrations structures or even remove or
117 * append additional migrations to the discovery. For example, this
118 * implementation filters out Drupal 6 migrations from the discovered migration
119 * list. This is done by checking the migration tags.
121 * @param array[] $migrations
122 * An associative array of migrations keyed by migration ID. Each value is the
123 * migration array, obtained by decoding the migration YAML file and enriched
124 * with some meta information added during discovery phase, like migration
125 * 'class', 'provider' or '_discovered_file_path'.
129 function hook_migration_plugins_alter(array &$migrations) {
130 $migrations = array_filter($migrations, function (array $migration) {
131 $tags = isset($migration['migration_tags']) ? (array) $migration['migration_tags'] : [];
132 return !in_array('Drupal 6', $tags);
137 * @} End of "addtogroup hooks".