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;
});