feed-me icon indicating copy to clipboard operation
feed-me copied to clipboard

Formatting is lost when updating Redactor field with FeedMe

Open Sam-Black-0013 opened this issue 5 years ago • 14 comments

When i try to update a Redactor field (a Commerce product description field), the content is updated, but when i output its content they appear without formatting. I have to open the product page, save it, refresh the product page, and then it works. The formatting is visible in the cp before resaving, but it just need a resave to take effect. I used the raw filter and without it, but with the same problem. I am not sure if i should post this issue here, or in FeedMe.

Craft: 3.1.34 Commerce: 2.1.8 Redactor: 2.3.3.2 FeedMe: ^4.1

Sam-Black-0013 avatar Jul 10 '19 13:07 Sam-Black-0013

Also having what appears to be this issue. The formatting is shown within the field but doesn't "work" on the front end, even when using the |raw filter. The HTML tags just aren't rendered at all.

I've found that simply re-saving the entry doesn't help. Instead I have to actually edit the redactor field and then save the entry. When I do that the HTML formatting returns on the front end.

Craft: 3.4.15 FeedMe: 4.2.2 Redactor: 2.6.1

peteeveleigh avatar Apr 18 '20 16:04 peteeveleigh

Having the same issue myself. One front-end of the site none of the formatting shows up after import. I have to go into the editor (where the formatting displays as expected) and manually add some newlines to the redactor field and resave. That preserves the formatting. Just saving without editing the field does nothing.

marcc1213 avatar Apr 30 '20 21:04 marcc1213

I just came across this same problem but found that if you wrap your html with a CDATA section, it will import into a redactor field as expected (I've only tested this with an XML import):

<projects>
        <project>
                <title>Project #1</title>
                <project_content><![CDATA[<p>Some html</p><p>All the <i>formatting</i></p>]]></project_content>
        </project>
        ...
</projects>

danbrellis avatar May 19 '20 15:05 danbrellis

This problem is still persisting.

Craft: 3.5.8 FeedMe: 4.2.3 Redactor: 2.7.4

Our content has the CDATA tag wrapped around it and it still is failing to import correctly. As previous users have stated the formatting shows correctly within the field, but not on the front end when rendered.

The field in the database where the actual content is being stored does not have the html formatting in it. After making a minor edit to the content in the CP and saving, the database field is updated with all the correct html formatting.

Haven't been able to find a work around other than to edit and save each and every field.

frank-rocketpark avatar Sep 10 '20 20:09 frank-rocketpark

I'm getting this issue. If you look in the code view of the Redactor field you can see the <p> tags are there but they're not rendered on the frontend:

image

Rendered: image

You have to modify the formatting or add a new line in Redactor field and save to get it to render correctly.

Craft CMS 3.5.12.1 Feed Me 4.2.4 Redactor 2.8.1

andrewhawkes avatar Oct 15 '20 13:10 andrewhawkes

Also experiencing this issue.

Craft Pro 3.6.7 Feedme 4.3.5.1 Redactor 2.8.5

gavinplatt avatar May 27 '21 14:05 gavinplatt

Anybody figure this out? Am also getting this issue

malcolmhmaclean avatar Jul 05 '21 15:07 malcolmhmaclean

Run into the same issue as well - manually adding a line and saving the entry again resolves the issue but that's a pain with alot of imported entries.

mmc501 avatar Aug 03 '21 10:08 mmc501

Just encountered this issue again. On a previous project, I parsed all HTML content heavily with a node script before importing. Don't have so much time on my current project so my workaround is on the template side using nl2br and craft's purify filter.

Incase it's helpful:

{%- if '<p>' in entry.redactor|raw -%}
  {{entry.redactor}}
{%- else -%}
  <p>{{entry.redactor|nl2br|purify}}</p>
{%- endif -%}

tomkiss avatar Dec 29 '21 12:12 tomkiss

Still have this issue Craft 3.7.17.2 with Redactor 2.8.8. @tomkiss thanks for the work around. That worked in many cases but presented some issues in other cases.

If you copy the source from the redactor field, paste and resave it solves the issue.

beckbailey avatar Jan 27 '22 21:01 beckbailey

I am also still having this issue. Would be great if a fix was released for this!

josh-attwood avatar Mar 21 '22 16:03 josh-attwood

Also still getting this issue

DowleyDeveloped avatar Jun 10 '22 13:06 DowleyDeveloped

Still an issue.

bdnorris avatar Jul 18 '22 21:07 bdnorris

Yes, still an issue.

AmericanTrails avatar Jul 29 '22 21:07 AmericanTrails

Still an issue under "craftcms/cms": "4.3.4" + "craftcms/feed-me": "5.0.4"...

romainpoirier avatar Dec 07 '22 14:12 romainpoirier

We're getting this issue after a large FeedMe import too. Again, like others, a change to the content fixes the issue, but we've got just over 1000 entries, and that would take some time.

russclewett-mw avatar Jan 06 '23 11:01 russclewett-mw

First off, I'm sorry because I don't have great news.

This issue occurs when the import data has something like \n instead of actual HTML. When that happens, the data is imported and stored in the database as is (with the \n value). When that value renders within the control panel, Redactor is initialized and will convert it to use <p> tags via JS. From there, when the entry is updated, the new value (with <p> tags) is sent to Craft and saved.

Redactor does all this in JS, which means we can't transform the values in the same way when parsing a field during an import because we don't have a JS runtime there.

I'm a little hesitant to implement some opinionated transformation around this because everyone's use case (and data) is a little different, and it feels like a bit of a Sisyphean task to try to handle them all.

That being said, there is an EVENT_AFTER_PARSE_FIELD event that will let you transform the parsed value before it is set when the feed is processing.

use craft\feedme\events\FieldEvent;
use craft\feedme\services\Fields;

Event::on(  
    Fields::class,  
    Fields::EVENT_AFTER_PARSE_FIELD,  
    function (FieldEvent $event) {  
        if ($event->fieldHandle === 'yourFieldHandle') {  
            $initialValue = $event->parsedValue;  
            // Mess with the value as needed and set it to `$newValue`
            
            $event->parsedValue = $newValue;  
        }  
    }
);

This event (and its EVENT_BEFORE_PARSE_FIELD sibling) are currently missing from the docs, so I've opened #1215 to add them to the docs.

I'm going to close this issue for the moment, but happy to keep the conversation going if someone has a good way to solve this that I'm not considering.

brianjhanson avatar Jan 09 '23 20:01 brianjhanson

It's a shame there isn't a server-side / PHP version of the Redactor parser to solve this with.

tomkiss avatar Jan 09 '23 21:01 tomkiss