【问题标题】:Migration pre-import event/event-listener迁移预导入事件/事件监听器
【发布时间】:2017-10-17 23:14:46
【问题描述】:

所以我有一个自定义的 Drupal 8 迁移,我们从 XML 导入节点 - 一切都很好。现在我想添加一个预导入功能,以便在迁移之前。在 Drupal 7 Migrate 中有 preImport() - Drupal 8 方法是什么?我找到了这篇关于 Events added to migration process 的文章,但我仍然不清楚如何继续...感谢任何提示!

【问题讨论】:

    标签: drupal drupal-8 migrate event-listener


    【解决方案1】:

    您需要创建自己的事件订阅者,这里有一个简短的指南:https://www.chapterthree.com/blog/how-to-register-event-subscriber-drupal8

    这里是一个 EventSubscriber 的具体示例(my_migration/src/EventSubscriber/PreImportEvent.php):

    <?php
    
    namespace Drupal\my_migration\EventSubscriber;
    
    use Drupal\migrate\Event\MigrateEvents;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    /**
     * Class PreImportEvent
     *
     * @package Drupal\my_migration\EventSubscriber
     */
    class PreImportEvent implements EventSubscriberInterface {
    
      /**
       * @return mixed
       */
      public static function getSubscribedEvents() {
        $events[MigrateEvents::PRE_IMPORT][] = [
          'preImport',
          0,
        ];
        return $events;
      }
    
      /**
       * @param $event
       */
      public function preImport($event) {
        // Do whatever you want with $event
      }
    
    }
    

    现在您需要为您的 EventSubscriber 注册服务 (my_migration/my_migration.services.yml):

    services:
      my_migration.subscriber.pre_import:
        class: Drupal\my_migration\EventSubscriber\PreImportEvent
        tags:
          - { name: event_subscriber }
    

    注意:如果您需要更改每个字段库的迁移,您最好使用 process 插件 (https://www.drupal.org/docs/8/api/migrate-api/migrate-process-plugins)。

    【讨论】:

      猜你喜欢
      • 2020-08-28
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 2021-03-24
      • 1970-01-01
      相关资源
      最近更新 更多