class PluginEventSubscriber

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/PluginEventSubscriber.php \Drupal\migrate\Plugin\PluginEventSubscriber
  2. 10 core/modules/migrate/src/Plugin/PluginEventSubscriber.php \Drupal\migrate\Plugin\PluginEventSubscriber
  3. 11.x core/modules/migrate/src/Plugin/PluginEventSubscriber.php \Drupal\migrate\Plugin\PluginEventSubscriber

Event subscriber to forward Migrate events to source and destination plugins.

Hierarchy

  • class \Drupal\migrate\Plugin\PluginEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of PluginEventSubscriber

1 string reference to 'PluginEventSubscriber'
migrate.services.yml in core/modules/migrate/migrate.services.yml
core/modules/migrate/migrate.services.yml
1 service uses PluginEventSubscriber
migrate.plugin_event_subscriber in core/modules/migrate/migrate.services.yml
Drupal\migrate\Plugin\PluginEventSubscriber

File

core/modules/migrate/src/Plugin/PluginEventSubscriber.php, line 15

Namespace

Drupal\migrate\Plugin
View source
class PluginEventSubscriber implements EventSubscriberInterface {
    
    /**
     * Tries to invoke event handling methods on source and destination plugins.
     *
     * @param string $method
     *   The method to invoke.
     * @param \Drupal\migrate\Event\MigrateImportEvent|\Drupal\migrate\Event\MigrateRollbackEvent $event
     *   The event that has triggered the invocation.
     * @param string $plugin_interface
     *   The interface which plugins must implement in order to be invoked.
     */
    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);
        }
    }
    
    /**
     * Forwards pre-import events to the source and destination plugins.
     *
     * @param \Drupal\migrate\Event\MigrateImportEvent $event
     *   The import event.
     */
    public function preImport(MigrateImportEvent $event) {
        $this->invoke('preImport', $event, ImportAwareInterface::class);
    }
    
    /**
     * Forwards post-import events to the source and destination plugins.
     *
     * @param \Drupal\migrate\Event\MigrateImportEvent $event
     *   The import event.
     */
    public function postImport(MigrateImportEvent $event) {
        $this->invoke('postImport', $event, ImportAwareInterface::class);
    }
    
    /**
     * Forwards pre-rollback events to the source and destination plugins.
     *
     * @param \Drupal\migrate\Event\MigrateRollbackEvent $event
     *   The rollback event.
     */
    public function preRollback(MigrateRollbackEvent $event) {
        $this->invoke('preRollback', $event, RollbackAwareInterface::class);
    }
    
    /**
     * Forwards post-rollback events to the source and destination plugins.
     *
     * @param \Drupal\migrate\Event\MigrateRollbackEvent $event
     *   The rollback event.
     */
    public function postRollback(MigrateRollbackEvent $event) {
        $this->invoke('postRollback', $event, RollbackAwareInterface::class);
    }
    
    /**
     * {@inheritdoc}
     */
    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;
    }

}

Members

Title Sort descending Modifiers Object type Summary
PluginEventSubscriber::getSubscribedEvents public static function
PluginEventSubscriber::invoke protected function Tries to invoke event handling methods on source and destination plugins.
PluginEventSubscriber::postImport public function Forwards post-import events to the source and destination plugins.
PluginEventSubscriber::postRollback public function Forwards post-rollback events to the source and destination plugins.
PluginEventSubscriber::preImport public function Forwards pre-import events to the source and destination plugins.
PluginEventSubscriber::preRollback public function Forwards pre-rollback events to the source and destination plugins.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.