<p>Just looking through the source file, it looks like <code>sectionId</code>, <code>typeId</code>, <code>authorId</code>, <code>postDate</code> and <code>expiryDate</code> are all set as properties on the <code>$entryRecord</code> before the <code>onBeforeSaveUser</code> event is fired. It also looks like <code>$entryRecord</code> is not accessible from the event, nor is it saved yet such that you could modify it directly. I suspect that you will need to modify these properties after the entry is saved (using the <code>onSaveEntry</code> event), and then resave the entry. You will also of course need to add conditionals (i.e. compare current authorId to target authorId) and only save the entry if needed, to ensure that you don't create an endless loop.</p>

CC BY-SA 3.0
2015-01-21T17:31:35.283Z
2015-01-21T17:31:35.283Z
Douglas McDonald
<p>With my plugin I listen for <a href="http://buildwithcraft.com/docs/plugins/events-reference#entries-onBeforeSaveEntry" rel="nofollow"><code>onBeforeSaveEntry</code></a> events and make changes to the <code>$entry</code> EntryModel. It works and I can change most properties from this function, but I have problems updating <code>sectionId</code>, <code>typeId</code>, <code>authorId</code>, <code>postDate</code> and <code>expiryDate</code>.</p>

<p>I looked up the relevant code in <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/EntriesService.php" rel="nofollow"><code>EntriesService.php</code></a> and noticed that it might have something to do with a variable <code>$entryRecord</code> that gets saved to the DB separately (comment in the code: <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/EntriesService.php#L214" rel="nofollow">"Save the actual entry row"</a>).</p>

<p>Am I doing something wrong or is it simply not possible to set these properties from this function. As an alternative solution I could trigger a seperate <code>saveEntry()</code> from here, but this looks to be not the cleanest solution.</p>

<pre><code>craft()-&gt;on('entries.onBeforeSaveEntry', function(Event $event)
{
    // Disable the entry
    $event-&gt;params['entry']-&gt;enabled = false;

    // Change the `authorId` (does NOT work!)
    $event-&gt;params['entry']-&gt;authorId = 1;
});
</code></pre>

<plugin-development><entrymodel>
Use `onBeforeSaveEntry` event to update EntryModel properties?
# Use `onBeforeSaveEntry` event to update EntryModel properties?

(Asked by: username_0 on 2015-01-21)

With my plugin I listen for onBeforeSaveEntry events and make changes to the $entry EntryModel. It works and I can change most properties from this function, but I have problems updating sectionId, typeId, authorId, postDate and expiryDate.
I looked up the relevant code in EntriesService.php and noticed that it might have something to do with a variable $entryRecord that gets saved to the DB separately (comment in the code: "Save the actual entry row").
Am I doing something wrong or is it simply not possible to set these properties from this function. As an alternative solution I could trigger a seperate saveEntry() from here, but this looks to be not the cleanest solution.
craft()->on('entries.onBeforeSaveEntry', function(Event $event)
{
    // Disable the entry
    $event->params['entry']->enabled = false;

    // Change the `authorId` (does NOT work!)
    $event->params['entry']->authorId = 1;
});

**Tags:** plugin-development, entrymodel

---

## 1 answers

### Answer by username_1 on 2015-01-21. Score: 2 | Accepted answer

Just looking through the source file, it looks like `sectionId`, `typeId`, `authorId`, `postDate` and `expiryDate` are all set as properties on the `$entryRecord` before the `onBeforeSaveUser` event is fired. It also looks like `$entryRecord` is not accessible from the event, nor is it saved yet such that you could modify it directly. I suspect that you will need to modify these properties after the entry is saved (using the `onSaveEntry` event), and then resave the entry. You will also of course need to add conditionals (i.e. compare current authorId to target authorId) and only save the entry if needed, to ensure that you don't create an endless loop.


---

