How to add additional text or punctuation around imported fields in migrations to Drupal 8

If you just need to get some text or characters in between fields your combining to gether, the concat (concatenation) plugin is all you need.

process:
  title:
    plugin: concat
    source:
      - movie_name
      - release_year
    delimiter: ' — '

You need to use single quotes in defining the delimiter.

If you want to do something abit more complex,

constants:
  INTRO: 'Announcing: '
  OUTRO: ' ...exactly as you\'ve seen it before'
  OPENPAREN: ' ('
  CLOSEPAREN: ')'
process:
  title:
    plugin: concat
    source:
      - constants/INTRO
      - movie_name
      - constants/OUTRO
      - constants/OPENPAREN
      - release_year
      - constants/CLOSEPAREN

Note that if using constants to inject strings, you probably don’t want to use a delimiter, as that would be added between both your real fields and the added strings (constants).

It’s quite bizarre that it accepts constants set to strings but not actual strings, but so be it. A simple workaround.

It should be possible to use pseudofields, defined at the same level of real fields and entity properties (e.g. body/value and title) and referenced with an @ symbol, ‘@mypseudofield’. This would allow even more complex logic, such as providing different intermediary or closing text depending on field values.