Score:0

Import multiple images with sub_process and image_import

to flag

I have some nodes with multiple images I want to import. How can I combine sub_process plugin with image_import?

"field_image":[
    {"src":"https://example.com/image1.png","alt":"Image 1","title":"Image one."}, 
    {"src":"https://example.com/image2.png","alt":"Image 2","title":"Image two"}
]

What can I do to loop throw the array of images and import them later.

Here is example of my YML migration process configuration

process:
  nid: nid
  title: title
  field_image:
    plugin: sub_process
    source: field_image
    process:
      plugin: image_import
      source: src
      destination: constants/file_destination
      title: title
      alt: alt
Score:0
um flag

The YAML looks good although I fundamentally disagree with all these modules that try to inline several migrations into one.

I am not sure what your source plugin is. If I were doing this, I'd write a custom one by copying EmptySource and changing id = "empty", to id = "my_json_source" and change initializeIterator to return new \ArrayIterator(json_decode($this->configuration['json_path'], TRUE)['field_image']); and then

source:
  plugin: my_json_source
  json_path: path/to/my/json/file

That ought to work.

sea26.2 avatar
om flag
The question was specifically how to use the sub_process PROCESS plugin. Not how to set up the source.
Smartsheet eng avatar
um flag
Of course. You are right. You all are always right and know better than me. How could it be otherwise?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.