2017-05-18 26 views
0

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

回答

0

您需要创建自己的事件订户,这里的简短说明: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 } 

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