Migrating XML-elements into multiple paragraphs

Created on 17 September 2020, about 4 years ago
Updated 13 September 2024, 16 days ago

Problem/Motivation

I am kind of stuck with migrating multiple elements from a XML Source into paragraphs on a target node. It feels like I've googled the web several times, finding and trying same and similiar solutions again and again, without or only partly success so far.
I feel close to the final solution, but... only close.

Steps to reproduce

So what I have in my XML Source per node is something like this:

<keyfeatures>
      <keyfeature>
        <keyid>key11</keyid>
        <title>Lorem</title>
        <description>Example Description</description>
      </keyfeature>
      <keyfeature>
        <keyid>key12</keyid>
        <title>Ipsum</title>
        <description>Another Description</description>
      </keyfeature>
      <keyfeature>
 </keyfeatures>

Each Keyfeature should be a single paragraph, embedded in a Paragraphs Entity Reference Revisions field, that can hold any number of different paragraphs of any type.

Proposed resolution

Everything is fine with creating the paragraphs themselves like this:

uuid: 65ccd7b3-da3b-4d93-8a07-652f4fbe316e
langcode: en
status: true
dependencies:
  enforced:
    module:
      - typo3_migration
_core:
  default_config_hash: '-toPHlpQOTOBKjOQyFVDNJ4RWyJG_Z91f2AyxBMgQik'
id: product_paragraphs
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - paragraphs
migration_group: xml_content
label: 'Migrate content to paragraphs'
source:
  plugin: url
  data_fetcher_plugin: file
  data_parser_plugin: xml
  item_selector: /catalog/product/keyfeatures/keyfeature
  urls:
    - 'public://migrate/single.xml'
  fields:
    -
      name: productId
      label: productId
      selector: ../../productId
    -
      name: keytitle
      label: keytitle
      selector: title
    -
      name: description
      label: description
      selector: description
    -
      name: keyid
      label: keyid
      selector: keyid
  ids:
    keyid:
      type: string
process:
  field_headline: keytitle
  field_text: description
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: simple_text_element
migration_dependencies: {  }

What I've managed so far, is a working setup with this yml for the node then, BUT it is only working for elements, that only contain ONE single item in keyfeatures:

...
id: product
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags: {  }
migration_group: xml_content
label: 'Products import'
source:
  plugin: url
  data_fetcher_plugin: file
  data_parser_plugin: xml
  item_selector: /catalog/product
  urls:
    - 'public://migrate/single.xml'
  keys:
    - productId
  fields:
    -
      name: language
      label: language
      selector: language
    -
      name: name
      label: name
      selector: name
    -
      name: description
      label: description
      selector: description
    -
      name: productId
      label: productId
      selector: productId
    -
      name: keyid
      label: keyid
      selector: //keyfeatures/keyfeature/keyid
    -
      name: keyfeature
      label: keyfeature
      selector: //keyfeatures/keyfeature
  ids:
    productId:
      type: string
process:
  title:
    -
      plugin: get
      source: name
  langcode:
    plugin: default_value
    default_value: en
  body/value: description
  body/format:
    -
      plugin: default_value
      default_value: basic_html
  field_product_title:
    -
      plugin: get
      source: name
  pseudo_test_paragraph:
    plugin: migration_lookup
    migration: product_paragraphs
    source: keyid
  field_paragraphs_test:
    plugin: sub_process
    source:
      - '@pseudo_test_paragraph'
    process:
      target_id: '0'
      target_revision_id: '1'


destination:
  plugin: 'entity:node'
  default_bundle: product

For each content with multiple elements in "keyfeatures" I get this message when running the 'product' migration:

[error] Value is not a valid entity. (/var/www/html/web/modules/contrib/entity_reference_revisions/src/Plugin/DataType/EntityReferenceRevisions.php:117)

Seems like the proccess is not running through each keyfeature separatly, quite obvious... But how do I achieve this?
I tried something like this, which seemed logic to me... but no paragraphs were connected to nodes at all:

field_paragraphs_test:
    plugin: sub_process
    source: keyfeatures
    process:
      pseudo_paragraphs:
        plugin: migration_lookup
        migration: product_paragraphs
        source: keyid
      target_id:
        plugin: extract
        source: '@pseudo_paragraphs'
        index:
          - 0
      target_revision_id:
        plugin: extract
        source: '@pseudo_paragraphs'
        index:
          - 1

Can anyone help? I've been trying around for days now...

💬 Support request
Status

Active

Version

1.12

Component

Documentation

Created by

🇩🇪Germany netVidual

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024