1

I have a CSV export which is done by the "views_data_export" module. When exporting, a plain text field which contains a double quote ends up with a " HTML entitity in the CSV file. This doesn't make sense, and when Im importing this file, this leads to problems.

I'm actually working with Drupal 9.5.10 and different entities, but was able to reproduce this with a fresh Drupal 10.1 installation. I hope I didn't forget any important step in the description.

Steps to reproduce

  • Install Drupal 10.1 (10.1.3-dev)
  • Install the modules "drupal/views" and "drupal/views_data_export"
  • Create an Article node and set the title as >>Test "Hello" Test<<
  • Create a view "article export" and set the following:
    • Add a display of type "data export"
    • Set the content type filter to match Article nodes
    • Under Format > Settings choose "csv". Expand the "CSV Settings" section and uncheck "Strip HTML".
    • Make sure the "title" field is selected and the formatter is set to "Plain text". Uncheck "Link to the content".
    • Set the path and the filename to "all_articles.csv"
    • Save the view and call the path

Expected

A CSV file with this content:

title
"Test ""Hello"" Test"

Actual

A CSV file with this content:

title
"Test &quot;Hello&quot; Test"

Any ideas on how to get the HTML out of there? Simply activating "Strip HTML" is not good enough, since the real-world example also contains fields which are supposed to contain HTML. The export is coupled with an import, so that users can modify the CSV file and reimport it. So the HTML fields need to contai HTML and the other fields should not contain HTML.

1 Answer 1

0

In your view, go to Format and click "Settings" for your Data export.

Settings

Then, uncheck "Strip HTML"

enter image description here

That should give you full HTML output in your export.

This is the return:

enter image description here

4
  • Thanks for your reply, but I'm not sure you read all details in my question. I already have "Strip HTML" deactivated. With that, I get HTML in all fields, not just in those fields that actually contain HTML. For plain text fields, I don't want quotes being turned into HTML entities. Commented Aug 24, 2023 at 12:04
  • I edited the answer to show you the return is what you're actually looking for. I'm unsure why you're getting the results you are. You could also try changing your Enclosure to a single quote. I'm running this on Drupal 10.
    – cstls
    Commented Aug 25, 2023 at 12:41
  • Sorry for taking some time to get back to you. I think the reason is the Formatter which needs to be set for each column in the export view. I selected "Plain text" for the title column and did not change the formatter settings. It is configured here: /admin/config/content/formats/manage/plain_text There are filters like "Display any HTML as plain text" and "Convert line breaks into HTML (i.e. <br> and <p>)" activated for this. Commented Aug 30, 2023 at 14:39
  • So... There is a Formatter "Plain text", which is done by the class "FilterHtmlEscape", which converts some special characters to HTML entities. That sounds like what is happening here. But what can be selected on the view is actually a Formatter class. In my case Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter is selected. I don't even see where this correlates with the text format?! Commented Aug 30, 2023 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.