【问题标题】:Migrate taxonomy reference field into entity reference将分类参考字段迁移到实体参考
【发布时间】:2019-02-19 23:17:57
【问题描述】:

我正在尝试将附加到 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】:

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

    首先,为我的领域使用 sub_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
        )
     )
    

    希望这会有所帮助!干杯。

    【讨论】:

      猜你喜欢
      • 2012-10-21
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      相关资源
      最近更新 更多