1

Im trying to create nodes from CSV also with image in one image field. I'm using Migrate modul in Drupal 8 and Migrate from CSV. Data to node works fine, image download and copy works fine but in node i dont have that image, the image has also record in database but isn't connected with the node. There is my code, does anyone knows where can be the problem? Thanks a lot for advices. The image field is called - field_uvodni_obrazek and im using last Drupal 8.4.2

product_data.YML - node import

 dependencies:
      module:
        - migrate_source_csv
    id: product_data
    migration_group: product_migration
    migration_tags:
      - product
      - node
    label: Profile
    source:
      plugin: csv
      # Full path to the file.
      path: 'C:\Users\Hans\Documents\import.csv'
      # Column delimiter. Comma (,) by default.
      delimiter: '|'
      # Field enclosure. Double quotation marks (") by default.
      enclosure: '"'
      # The number of rows at the beginning which are not data.
      header_row_count: 1
      keys:
        - id
      column_names:
        0:
          id: 'id'
        1:
          kod: 'Kod zbozi'
        2:
          title: 'Nazev produktu'
        3:
          refstruct: 'Referenční struktura'
        4:
          kategorie: 'Kategorie produktu'
        5:
          objednani: 'Objednaci název'
        6:
          obrazek: 'Obrazek'
        7:
          popis: 'Krátky popis'
        8:
          rozsireny_popis: 'Rozsireny popis produktu'
    process:
      title: title
      field_produktove_cislo: kod
      field_objednaci_nazev: objednani
      field_refstruct: refstruct
      body/value: rozsireny_popis
      body/summary: popis
      field_kategorie_produktu:
        -
          plugin: explode
          delimiter: '/'
          source: kategorie
      field_uvodni_obrazek/target_id:
            plugin: migration_lookup
            migration: product_image
            source: obrazek
            no_stub: true
      field_uvodni_obrazek/alt:
         plugin: default_value
         default_value: title
      field_uvodni_obrazek/title:
        plugin: default_value
        default_value: title
      uid:
          plugin: default_value
          default_value: 1
      langcode:
               plugin: default_value
               default_value: 'cs'
      type:
        plugin: default_value
        default_value: produkt

    destination:
      plugin: 'entity:node'
      default_bundle: produkt
    migration_dependencies:
      optional:
        - product_image

product_image.YML - image import

id: product_image
label: Import all product images.
migration_group: product_migration
migration_tags:
  - product
  - file
  - image
source:
  plugin: csv
  path: 'C:\Users\Hans\Documents\import.csv'
  delimiter: '|'
  enclosure: '"'
  header_row_count: 1
  keys:
    - id
  column_names:
    0:
      id: 'id'
    6:
      filename: 'obrazek'
  constants:
    file_source_uri: public://import
    file_dest_uri: 'public://produkty/uvodni'
process:
  file_source:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_source_uri
        - filename
    -
      plugin: urlencode
  file_dest:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_dest_uri
        - filename
    -
      plugin: urlencode
  uid:
        plugin: default_value
        default_value: 1
  uri:
    plugin: file_copy
    source:
      - '@file_source'
      - '@file_dest'
  filename: filename
destination:
  plugin: 'entity:file'

1 Answer 1

1

You need to create a connection between image and node, a reference. You should set the fid. Have a look at this example. Also, in my case it was really helpful this post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.