Score:1

Use Node title as default value in alt field of field_image migration

nl flag

I've been working on a D7 to D9 migrate project, and encountered an issue around field_image's alt value.

The D7 site does not have all the field_image alt tag setup, so we'd like to use the imported Node Title as a replacement if the value was empty.

The migration config file works, all other fields are imported perfectly. Just the alt tag didn't make use of the replacement of '@title' instead (I saw other usage of @ syntax on other migration config files). All I saw was @title string within my alt field after importation.

How should I make it work? Thanks!

config/sync/migrate_plus.migration.upgrade_d7_node_complete_article.yml

langcode: en
status: true
dependencies: {  }
id: upgrade_d7_node_complete_article
class: Drupal\node\Plugin\migrate\D7NodeTranslation
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - 'Drupal 7'
  - Content
migration_group: migrate_drupal_7
label: 'Node complete (News)'
source:
  plugin: d7_node_complete
  node_type: article
process:
  nid:
    -
      plugin: get
      source: tnid
  vid:
    -
      plugin: get
      source: vid
  langcode:
    -
      plugin: default_value
      source: language
      default_value: und
  title:
    -
      plugin: get
      source: title
  field_image:
    -
      plugin: sub_process
      source: field_image
      process:
        target_id: fid
        alt:
          plugin: default_value
          source: alt
          default_value: '@title'
        title: title
        width: width
        height: height
destination:
  plugin: 'entity_complete:node'
  translations: true
  default_bundle: article
migration_dependencies:
  required:
    - upgrade_d7_user
    - upgrade_d7_node_type
    - upgrade_language
  optional:
    - upgrade_d7_field_instance
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.