2017-05-18 22 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)。