使用源csv进行Drupal 8自定义迁移

时间:2018-01-13 17:08:02

标签: csv plugins migration drupal-8

如何从密钥行中具有相同值的csv文件将字段导入Drupal 8用户配置文件?

我使用Migrate Tools,Migrate Plus和Migrate Source CSV。我的CSV文件如下所示:

"Stg";"Color";"Fruit"
"user1";"red";"apple"
"user1";"blue";"pear"
"user2";"green";"banana"
"user2";"black";"rotten banana"

我正在使用个人资料模块(https://www.drupal.org/project/profile

我的迁移组中有一个如下所示的迁移(migrate_plus.migration.user_vorlesungen.yml):

id: user_vorlesungen
langcode: de
status: true
dependencies:
    enforced:
        module:
            - user_migrate
migration_group: hoevwa
label: 'HoeVWA Vorlesungen Import'
source:
    plugin: csv
    track_changes: true
    path: /config/Vorlesungsverzeichnis.csv
    # Column delimiter. Comma (,) by default.
    delimiter: ';'
    # Field enclosure. Double quotation marks (") by default.
    enclosure: '"'
    header_row_count: 1
    keys:
        - Stg
destination:
    plugin: entity:profile
process:
    type:
        plugin: default_value
        default_value: 'vorlesungen'
    uid:
        plugin: migration_lookup
        no_stub: true
        # previous user migration
        migration: user__hoerer
        # property in the source data
        source: Stg
    # These field have multiple values in D8
    field_color: Color
    field_fruit: Fruit

migration_dependencies:
    required: {  }
    optional: {  }

在我的YAML文件中,内容的打印方式如下:

...
<table>
  <tr>
    <td>{{ content.field_color }}</td>
    <td>{{ content.field_fruit }}</td>
  </tr>
</table>
...

当我运行drush mim --group = hoevwa时,只导入user1(blue,pear)的最后一个值。如何运行流程插件以循环CSV并获取所有值。最后,我如何遍历我的TWIG模板中的所有值?

0 个答案:

没有答案