Score:1

How migrate rich text fields from outside Drupal without converting html tags to entities

pe flag

I'm working on a migration from a non-Drupal site into Drupal 9. So far, I'm using migrate_plus, migrate_tools, and migrate_source_csv modules. The data I'm importing has <br> and other tags in some fields. When these import, the <br> tags are visible on site pages after the migration completes.

The source is a tab delimited file.

Looking at the page code, these are rendering as html entities instead of tags: so <br> is &lt;br&gt;

I've tried changing settings many different ways in the basic HTML filter these fields use. No change.

I added a plugin for each of these fields that is, I thought, supposed to call the basic_html filter. This also had no impact.

The two fields are field_perm_contact_info and body.

Here's the relevant portion of my import configuration yaml file...

process:
  type:
    plugin: default_value
    default_value: source
  field_source_id: srcid
  title: title
    field_source_country: 
    plugin: entity_generate
    source: country
    value_key: name
    bundle: country
    entity_type: taxonomy_term
    ignore_case: true
  field_srcfax: fax
  field_main_link: mainlink
  field_manualyr: manual
  field_perm_contact_info: 
    plugin: default_value
    default_value: basic_html
    source: permcontinf
  field_permpdfname: permpdf
  field_perm_scope: permscope
  field_perm_updated:
    plugin: format_date
    from_format: n/j/Y
    to_format: Y-m-d
    source: permupdated
  field_tpop: pop
  field_rev_dateleg:
    plugin: format_date
    from_format: n/j/Y
    to_format: Y-m-d
    source: revdate
  field_short_name: shortname
  field_source_iacp_id: srciacpid
  body:
    plugin: default_value
    default_value: basic_html
    source: srcnotes  
destination:
  plugin: entity:node

My basic_html filter has <br> in the allowed tags list.

If I open an imported node and and resave, boom, it looks fine. So the question is, how to do the import so that the end result is rendered HTML, not tags displayed as html entities?

A good bit of googling hasn't gotten me to the answer to that yet.

Score:2
cn flag

One way is to set the value and format separately:

constants:
  text_format: basic_html
process:
  field_perm_contact_info/value: permcontinf
  field_perm_contact_info/format: constants/text_format
  body/value: srcnotes
  body/format: constants/text_format
pe flag
Thanks, will give this a try... This page also provided clues: https://drupal.stackexchange.com/questions/281659/how-to-migrate-text-format I wasn't thinking of the format as a separate setting.
Score:0
pe flag

I'm not familiar with the use of 'constant,' so the "set the value format separately" (thanks @Clive) for my two rich text fields looks like this in my yaml file...

  field_perm_contact_info/value: permcontinf 
  field_perm_contact_info/format:
    plugin: default_value
    default_value: basic_html
  field_permpdfname: permpdf
  field_perm_scope: permscope
  field_perm_updated:
    plugin: format_date
    from_format: n/j/Y
    to_format: Y-m-d
    source: permupdated
  field_tpop: pop
  field_rev_dateleg:
    plugin: format_date
    from_format: n/j/Y
    to_format: Y-m-d
    source: revdate
  field_short_name: shortname
  field_source_iacp_id: srciacpid
  body/value: srcnotes
  body/format: 
    plugin: default_value
    default_value: basic_html 

The key concept is to handle the text field like two 'subfields' (this post also helpful), one of them being format.

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.