1

I'm trying to import image with new media module on core 8.5.

I've a json source and on my .yml I've:

  field_media_image:
    target_id:
      plugin: migration
      migration: immagini
      source: fid

This works, immagini is another importer that imports files.

In the new media there is also an "alt" (mandatory) and "title" attribute on the media entity. But if I try to add something like this, it doesn't work (alt_text is the correct source for alternative text). The media is created but is not referenced to the correct id:

  field_media_image:
    alt: alt_text
    target_id:
      plugin: migration
      migration: immagini
      source: fid

How should I pass the alt attribute to this field? I also tried to use a syntax like:

  field_media_image:
    target_id:
      plugin: migration
      migration: immagini
      source: fid
  'field_media_image/alt': alt_text

But it doesn't work, the media is created but there is no reference to the correct id.

0

field_media_image/alt belongs in the immagini migration, not in the node migration.

In migration that creates the media item (destination plugin entity:media) you can map the media item's fields:

  # Image field see media_entity.bundle.image.yml.
  field_media_image/target_id: fid
  field_media_image/alt: field_file_image_alt_text/0/value
  field_media_image/title: field_file_image_title_text/0/value

  # Description field.
  field_description: field_image_description
  # Caption field.
  field_caption: field_caption

destination:
  plugin: entity:media

See https://www.previousnext.com.au/blog/migrating-drupal-7-file-entities-drupal-8-media-entities

Your Answer

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

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