<p>The <code>EVENT_STEP_BEFORE_ELEMENT_SAVE</code> is actually fired after the content has been applied to element attributes and field content.</p>

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

<pre><code>$event-&gt;element-&gt;productDescription = " - blah - ";  
</code></pre>

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

<p>Let me know if that doesn't work!</p>

CC BY-SA 4.0
2019-02-15T04:57:24.583Z
2019-02-15T04:57:24.583Z
crawf
<p>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. </p>

<pre><code>Event::on(Process::class, Process::EVENT_STEP_BEFORE_ELEMENT_SAVE, function(FeedProcessEvent $event) {
 $event-&gt;contentData['productDescription'] = " - blah - ";         
}); 
</code></pre>

<p>Here's the logging (irrelevant data omitted):</p>

<pre><code>{before modifying ($contentData) ==== "productDescription":"Freestanding Spring Horses"}
{after modifying ($contentData) ::::: "productDescription":" - blah - "}
{Data ready to import ($contentData) -&gt; "productDescription":" - blah - "}
{After saving ($contentData) ---- "productDescription":" - blah - "}
</code></pre>

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

<p>So how can I modify the data that gets saved for each element?</p>

<plugin-feedme>
How to modify element's data during import?
# How to modify element's data during import?

(Asked by: username_0 on 2019-02-14)

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?

**Tags:** plugin-feedme

---

## 1 answers

### Answer by username_1 on 2019-02-15. Score: 1

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!


---

