Skip to content
Snippets Groups Projects
Select Git revision
  • 0308eb77d42e2fd1e6e97138e590061d17a69390
  • 11.x default protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

PluginEventSubscriber.php

Blame
  • Alex Pott's avatar
    Issue #2485385 by phenaproxima, quietone, Berdir, blazey, hussainweb,...
    Alex Pott authored
    Issue #2485385 by phenaproxima, quietone, Berdir, blazey, hussainweb, mikeryan, benjy, alexpott: Move highwater field support to the source plugin, and do not expose its internals on MigrationInterface
    0308eb77
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PluginEventSubscriber.php 2.89 KiB
    <?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;
    
    /**
     * Event subscriber to forward Migrate events to source and destination plugins.
     */
    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;
      }
    
    }