Change record status: 
Project: 
Introduced in branch: 
8.0.x
Description: 

Migrate now dispatches events at key transition points in the migration process. This will enable contrib tools to better monitor and control the migration process without specific core support for any such features, and also will enable custom migration modules to affect the migration process (such as modifying an item just before saving it).

To register event listeners in your class, add the listeners in your constructor:

public function __construct() {
  \Drupal::service('event_dispatcher')->addListener(MigrateEvents::MAP_SAVE, array($this, 'onMapSave'));
}

or implement EventSubscriberInterface with a getSubscribedEvents() static method:

class Example implements EventSubscriberInterface {

  public static function getSubscribedEvents() {
    $events[MigrateEvents::MAP_SAVE][] = ['onMapSave'];
    return $events;
  }

}

The following events have been added:

MigrateEvents::MAP_SAVE (migrate.map_save) - Just before inserting or updating an id map entry (which records the disposition of a source item), dispatches MigrateMapSaveEvent.

public function onMapSave(MigrateMapSaveEvent $event) {
  // Map object dispatching the event.
  $map = $event->getMap();
  // Array of fields (keyed by column name) to be saved to the map. 
  $fields = $event->getFields();
}

MigrateEvents::MAP_DELETE (migrate.map_delete) - Just before deleting an id map entry (such as when it's being rolled back), dispatches MigrateMapDeleteEvent.

public function onMapDelete(MigrateMapDeleteEvent $event) {
  // Map object dispatching the event.
  $map = $event->getMap();
  // Array of source ID values (keyed by column name) of the map entry to be deleted.. 
  $fields = $event->getSourceId();
}

MigrateEvents::PRE_IMPORT (migrate.pre_import) - Dispatched just before beginning the import of a specific migration.

public function onPreImport(MigrateImportEvent $event) {
  // Migration object about to begin import.
  $migration = $event->getMigration();
}

MigrateEvents::POST_IMPORT (migrate.post_import) - Dispatched just before completion of the import of a specific migration.

public function onPostImport(MigrateImportEvent $event) {
  // Migration object just finished importing.
  $migration = $event->getMigration();
}

MigrateEvents::POST_ROW_SAVE (migrate.post_row_save) - Dispatched just after the import of a given row within a migration.

public function onPostRowSave(MigratePostRowSaveEvent $event) {
  // Migration object being imported.
  $migration = $event->getMigration();
  // Row object containing the specific item just imported.
  $row = $event->getRow();
  // The unique destination ID, as an array (accomodating multi-column keys), of the item just imported.
  $destination_id_values = $event->getDestinationIdValues();
}
Impacts: 
Module developers