I'm trying to modify the element's data during the import. I'm using EVENT_STEP_BEFORE_ELEMENT_SAVE to modify the $contentData. I added some logging at each step and I can see that the $contentData is being changed to " - blah - " for each element in the feed but the original value for 'productDescription' is still being saved for the element.

Event::on(Process::class, Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, function(FeedProcessEvent $event) {
 $event->contentData['productDescription'] = " - blah - ";         

Here's the logging (irrelevant data omitted):

{before modifying ($contentData) ==== "productDescription":"Freestanding Spring Horses"}
{after modifying ($contentData) ::::: "productDescription":" - blah - "}
{Data ready to import ($contentData) -> "productDescription":" - blah - "}
{After saving ($contentData) ---- "productDescription":" - blah - "}

When I look at the productDescription field for the element that was just imported I see: "Freestanding Spring Horses"

So how can I modify the data that gets saved for each element?


The EVENT_STEP_BEFORE_ELEMENT_SAVE is actually fired after the content has been applied to element attributes and field content.

Instead, you'll want to modify the element's content directly. You can do this via:

$event->element->productDescription = " - blah - ";  

As the plugin author, I may change this so it acts as you've suggested. Currently, modifying $contentData essentially does nothing. However, this will require a change to the event where it passes in attributeData and fieldData separately, as they need to be applied separately back on the element. I'll look at adding this in the next version.

Let me know if that doesn't work!

| improve this answer | |

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.