Drupal  8.2.6
API documentation
Data Structures | Functions
Migration API

Data Structures

class  MigrateDestination
 
class  MigrateProcessPlugin
 
class  MigrateSource
 
class  DestinationBase
 
class  SourcePluginBase
 
interface  MigrateDestinationInterface
 
class  MigrateDestinationPluginManager
 
class  MigratePluginManager
 
interface  MigrateProcessInterface
 
interface  MigrateSourceInterface
 
class  MigrateSourcePluginManager
 
class  ProcessPluginBase
 
class  CckFieldPluginBase
 
class  MigrateCckFieldPluginManager
 

Functions

 hook_migrate_prepare_row (Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
 
 hook_migration_plugins_alter (array &$migrations)
 

Detailed Description

Overview of the Migration API, which migrates data into Drupal.

Overview of migration

Migration is an Extract, Transform, Load (ETL) process. In the Drupal migration API the extract phase is called "source", the transform phase is called "process", and the load phase is called "destination". It is important to understand that the "load" in ETL means to load data into storage, while traditionally Drupal uses "load" to mean load data from storage into memory.

In the source phase, a set of data, called the row, is retrieved from the data source, typically a database but it can be a CSV, JSON or XML file. The row is sent to the process phase where it is transformed as needed by the destination, or marked to be skipped. Processing can also determine that a stub needs to be created, for example, if a term has a parent term that does not yet exist. After processing the transformed row is passed to the destination phase where it is loaded (saved) into the Drupal 8 site.

The ETL process is configured by the migration plugin. The different phases: source, process, and destination are also plugins, and are managed by the Migration plugin. So there are four types of plugins in the migration process: migration, source, process and destination.

Migration plugins

Migration plugin definitions are stored in a module's 'migrations' directory. For backwards compatibility we also scan the 'migration_templates' directory. Examples of migration plugin definitions can be found in 'core/modules/action/migration_templates'. The plugin class is , with interface . Migration plugins are managed by the class. Migration plugins are only available if the providers of their source plugins are installed.

Source plugins

Migration source plugins implement and usually extend . They are annotated with annotation, and must be in namespace subdirectory Plugin under the namespace of the module that defines them. Migration source plugins are managed by the class. Source plugin providers are determined by their and their parents namespaces.

Process plugins

Migration process plugins implement and usually extend . They are annotated with annotation, and must be in namespace subdirectory Plugin under the namespace of the module that defines them. Migration process plugins are managed by the class. The Migrate module provides process plugins for common operations (setting default values, mapping values, etc.).

Destination plugins

Migration destination plugins implement and usually extend . They are annotated with annotation, and must be in namespace subdirectory Plugin under the namespace of the module that defines them. Migration destination plugins are managed by the class. The Migrate module provides destination plugins for Drupal core objects (configuration and entity).

More information

Migration API documentation.

See also
Update API

Function Documentation

◆ hook_migrate_prepare_row()

hook_migrate_prepare_row ( Row  $row,
MigrateSourceInterface  $source,
MigrationInterface  $migration 
)

Allows adding data to a row before processing it.

For example, filter module used to store filter format settings in the variables table which now needs to be inside the filter format config file. So, it needs to be added here.

hook_migrate_MIGRATION_ID_prepare_row() is also available.

Definition at line 104 of file migrate.api.php.

◆ hook_migration_plugins_alter()

hook_migration_plugins_alter ( array &  $migrations)

Allows altering the list of discovered migration plugins.

Modules are able to alter specific migrations structures or even remove or append additional migrations to the discovery. For example, this implementation filters out Drupal 6 migrations from the discovered migration list. This is done by checking the migration tags.

Parameters
array[]$migrations An associative array of migrations keyed by migration ID. Each value is the migration array, obtained by decoding the migration YAML file and enriched with some meta information added during discovery phase, like migration 'class', 'provider' or '_discovered_file_path'.

Definition at line 129 of file migrate.api.php.