PluginEventSubscriber.php in Drupal 9
File
core/modules/migrate/src/Plugin/PluginEventSubscriber.php
View source
<?php
namespace Drupal\migrate\Plugin;
use Drupal\migrate\Event\ImportAwareInterface;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\Event\MigrateImportEvent;
use Drupal\migrate\Event\MigrateRollbackEvent;
use Drupal\migrate\Event\RollbackAwareInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PluginEventSubscriber implements EventSubscriberInterface {
protected function invoke($method, $event, $plugin_interface) {
$migration = $event
->getMigration();
$source = $migration
->getSourcePlugin();
if ($source instanceof $plugin_interface) {
call_user_func([
$source,
$method,
], $event);
}
$destination = $migration
->getDestinationPlugin();
if ($destination instanceof $plugin_interface) {
call_user_func([
$destination,
$method,
], $event);
}
}
public function preImport(MigrateImportEvent $event) {
$this
->invoke('preImport', $event, ImportAwareInterface::class);
}
public function postImport(MigrateImportEvent $event) {
$this
->invoke('postImport', $event, ImportAwareInterface::class);
}
public function preRollback(MigrateRollbackEvent $event) {
$this
->invoke('preRollback', $event, RollbackAwareInterface::class);
}
public function postRollback(MigrateRollbackEvent $event) {
$this
->invoke('postRollback', $event, RollbackAwareInterface::class);
}
public static function getSubscribedEvents() {
$events = [];
$events[MigrateEvents::PRE_IMPORT][] = [
'preImport',
];
$events[MigrateEvents::POST_IMPORT][] = [
'postImport',
];
$events[MigrateEvents::PRE_ROLLBACK][] = [
'preRollback',
];
$events[MigrateEvents::POST_ROLLBACK][] = [
'postRollback',
];
return $events;
}
}