0

I am using migrate_source_csv to import node body fields. The header for my CSV file is: "nid, title, body". The body fields contain HTML. My problem is that, on import, the HTML is being encoded into literals. See the screen grab below. Here is my migration YML file:

id: news_article_nodes
label: News article data we want.
migration_group: gdg_group
source: 
  plugin: csv
  path: 'modules/custom/gdg_migration/import/news_article/news_articles.csv' 
  ids: [nid]
  header_row_count: 1
process:
  nid: nid
  title: title
  'body/0/value': body
  'body/0/format':
    plugin: default_value
    default_value: full_html
destination: 
   plugin: entity:node
   overwrite_properties:
     - body
   default_bundle: news_article

I must be missing something. Is there a plugin that imports the data as plain text?

screen shot of node body w/ encoded HTML

1

You could try to use PHP's html_entity_decode() on the source field:

process:
  nid: nid
  title: title
  body/value: 
    plugin: callback
    callable: html_entity_decode
    source: body
  body/format:
    plugin: default_value
    default_value: full_html

PS: You've written that your source CSV doesn't contain encoded entities... have you checked the display settings for your field? (Manage > Structure > Content types > NODE_TYPE > Manage display). It could be that the import is correct, but the render settings are incorrectly set to something like plain text or a |raw filter in a Twig template file.

  • Thanks. I tried that but same result. Interestingly, I am having this problem on Windows. I tried the same development environment on a Mac and it displays the HTML correctly. I am still trying to debug on Windows. – Dorian Winterfeld Dec 12 '19 at 17:34
-1

you have just to remove de /0/ from body field

 body/value: body
 body/format:
  plugin: default_value
  default_value: full_html
  • Thanks for the suggestion. Unfortunately, I am getting the same result. – Dorian Winterfeld Dec 9 '19 at 17:02
  • When I view source I can see that < is replaced with &lt;, > w/ &gt;, etc. This is not in the CSV file. Some thing is filtering the HTML on import. – Dorian Winterfeld Dec 9 '19 at 17:09

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.