How to import line breaks, keep backslashes in \r\n from getting escaped?

Created on 24 March 2025, 14 days ago

Problem/Motivation

I'd like to concatenate a few lines, containing an address, and keep them on separate lines after import, with this:

  constants:
    delimiter: ' \r\n '
[...]
process:
  field_address:
    plugin: concat
    source:
      - address_line1
      - 'constants/delimiter'
      - address_line2
      - 'constants/delimiter'
      - address_line3

... but the backslashes are escaped:

$ drush php:eval --format=json "return \Drupal::service('database')->query('select field_address_value from node_revision__field_address where entity_id=4235')->fetchAll()"
[
    {
        "field_address_value": "Street Name 25 \\r\\n 10532  City \\r\\n Country"
    }
]

Is there a way to avoid backslashes getting escaped, like this?

$ drush php:eval --format=json "return \Drupal::service('database')->query('select field_address_value from node_revision__field_address where entity_id=4235')->fetchAll()"
[
    {
        "field_address_value": "Street Name 25 \r\n 10532  City \r\n Country"
    }
]

Steps to reproduce

Proposed resolution

Perhaps a callable plugin can be used? https://www.drupal.org/docs/8/api/migrate-api/migrate-process-plugins/pr...

See also https://drupal.stackexchange.com/questions/286294/migrate-nodes-with-spe...

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

6.0

Component

Documentation

Created by

🇩🇰Denmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024