我正在尝试使用核心的迁移模块(Migrate module)、迁移来源CSV(Migrate Source CSV)、迁移工具(Migrate Tools)和迁移加强版(Migrate Plus),从一个CSV文件中填充一个新的Drupal 8(8.3.2)网站的内容。我能够成功地导入每个节点,并带有单张图片,但我不确定如何将多个图片迁移到节点的多值图像字段中。
我的模块目前如下所示:
我的模块目前如下所示:
id: product_data
label: Products
migration_group: product_migration
migration_tags:
- node
- product
source:
plugin: csv
path: 'public://import/products/products.full.csv'
header_row_count: 1
keys:
- product_sku
constants:
bool_0: 0
bool_1: 1
uid_root: 1
restricted_html: restricted_html
destination:
plugin: 'entity:node'
default_bundle: product
process:
title: product_name
field_sku: product_sku
sticky: constants/bool_0
promote: constants/bool_1
uid: constants/uid_root
'field_image/target_id':
plugin: migration
migration: product_image
source: product_full_image
migration_dependencies:
optional:
- product_image
dependencies:
enforced:
module:
- custom_migration
然后创建图像实体:
id: product_image
label: Images associated with a product.
migration_group: product_migration
migration_tags:
- product
- file
- image
source:
plugin: csv
path: 'public://import/products/products.full.csv'
header_row_count: 1
keys:
- product_full_image
fields:
product_full_image: Name of the image file associated with the program.
constants:
file_source_uri: public://import/products/old-images
file_dest_uri: 'public://program/image'
destination:
plugin: 'entity:file'
process:
file_source:
-
plugin: concat
delimiter: /
source:
- constants/file_source_uri
- product_full_image
-
plugin: urlencode
file_dest:
-
plugin: concat
delimiter: /
source:
- constants/file_dest_uri
- product_full_image
-
plugin: urlencode
filename: product_full_image
uri:
plugin: file_copy
source:
- '@file_source'
- '@file_dest'
dependencies:
enforced:
module:
- custom_migration
CSV文件的格式如下:
product_sku,product_name,product_full_image
C242,couch,Blue Couch,"image1.jpg,image2.jpg"
C243,chair,Red Chair,image3.jpg
我尝试过使用expload和iterator插件,但是说实话,我完全不知道该怎么做。如果您有任何想法,将不胜感激。