将分类法 引用字段迁移到实体引用中

问题描述 投票:0回答:1

我试图将附加到field_collection实体类型(Drupal 7)的分类法引用字段迁移到附加到段落实体类型(Drupal 8.6)的实体引用字段中。

虽然这似乎是迁移过程中的基本任务之一,但我找不到如何做到这一点的明确参考。

id: d7_field_collection_field_name
label: My Field name
migration_tags:
  - Drupal 7
migration_group: migrate_drupal_7

source:
  plugin: d7_custom_source_plugin
process:
  field_title:
    plugin: get
    source: field_title
  field_job_category:
    plugin: get
    source: field_job_category
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: my_paragraphs_bundle
migration_dependencies:
  required:
    - upgrade_d7_field
    - upgrade_d7_node_type
    - upgrade_d7_field_collection_type
    - upgrade_d7_field_instance

迁移过程在这里解释:https://www.mtech-llc.com/blog/ada-hernandez/migration-field-collection-d7-paragraphs-node-d8

所以,field_job_category不起作用。我在流程插件中尝试了很多方法而没有运气。例如,我用过:

  field_job_category:
    plugin: migration_lookup
    migration: upgrade_d7_taxonomy_term_job_categories
    source: term_id

然后尝试使用源,因为我使用Drupal 8.6

  field_job_category:
    plugin: migration_lookup
    migration: upgrade_d7_taxonomy_term_job_categories
    sources:
      upgrade_d7_taxonomy_term_job_categories:
        - term_id

我相信它在field_job_category下是一个配置错误,但我还是想不通。

非常感谢您的帮助!

drupal-8 configuration-files taxonomy paragraph entityreference
1个回答
0
投票

通过做两件事就解决了这个问题。

首先,为我的字段使用sub_process process插件。

field_job_category:
  -
    plugin: sub_process
    source: field_job_category
    process:
      target_id: tid

最后,实现hook_migrate_prepare_row()以提供具有正确结构的数据,以供上述子进程使用

$row->setSourceProperty($field_name, $new_value);

并且$ new_value应该是

Array
(
  [0] => Array
    (
        [tid] => Term ID
    )
 )

希望这可以帮助!干杯。

© www.soinside.com 2019 - 2024. All rights reserved.