I have a custom migration script that uses 4+ sheets to migrate data into two different content types (that reference each other), along with referenced users, and most important to my question, references media entities that I import/migrate as part of the tagged migration group.

I am able to successfully 1) import the image/file entities, then 2) create "proper" media entities from the file import and 3) reference a SINGLE media entity in one of the nodes (the business_branch node for each business location. The trouble is, I'm not able to use the migration_lookup plugin to attach more than one media entity to the respective node.

Ultimately, I want to create a business_branch node that has various business information (like hours of operation, address, etc), AND link up to 10 different media (images) to that node. I've got everything else migrating beautifully...but I can't get MULTIPLE media entity references to work. I have tried various other drupal migration plugins like explode and sub_process etc (or combinations thereof), but for whatever reason, the migration fails (probably because my process chain is not in the right order...or I'm straight up just trying to use the wrong plugins).

Anyway, I created an entire github repo just so it would be easier to answer this question: https://github.com/Doomd/GSheetsToDrupalMigration

To jump right into the particular details I need help with, here's the source Google Spreadsheet I'm using as the source: https://docs.google.com/spreadsheets/d/1GuKab6Ezi3GckSjMD5BmAQVa0qnOKJX9kadWz_mDxcU

On the first sheet of the Google Spreadsheet, I've highlighted the column I would LIKE to use to reference files/images on the second sheet (basically a string of file-id's that are semi-colon delimited). The second sheet contains the source data for the files themselves that are the source migration for 1) gstd_file_image.yml and then 2) gstd_file_image_to_media.yml (which are both migrations that happen before my primary node creation/migration on gstd_node_business_location.yml.

Here is the relevant excerpt from gstd_node_business_location.yml that successfully creates references to a SINGLE media entity. Note, I'm just including the parts for the Photo ID reference column source and destination field:

  - name: src_photo_id
    label: "Photo ID"
    selector: photoid
  # Single Photo Works...
    plugin: migration_lookup
    migration: gstd_file_image_to_media
    source: src_photo_id

So the SINGLE reference works. On the other hand, here is ONE (of the many) non-working approaches I've tried to use reference multiple Photo IDs (note, I've created a separate column in the source sheet for multiple IDs for testing purposes):

  - name: src_multi_photo_id
    label: "Multi Photo ID"
    selector: multiphotoid
  #attempt to link multiple media items per node (Doesn't work)
    - plugin: explode
      source: src_multi_photo_id
      delimiter: ";"
    - plugin: callback
      callable: trim
    - plugin: single_value
    - plugin: sub_process
          - plugin: migration_lookup
            migration: gstd_file_image_to_media
            source: src_multi_photo_id

Can you please help me correct this Drupal migration so that MULTIPLE media entity references work (similar to how I can reference multiple taxonomy terms to a taxonomy reference field)? Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.