I'm trying to modify a field on an entry before it is saved.
What I'm trying to do is use a field from a linked entry to populate the same field on the entry being saved.
From logging I know the event is triggered, and that I can access the seo
variable on the linked element.
Edit: The field I'm trying to copy the content from is the SEO field supplied by the sprout SEO plugin.
However when I try to set the field on the main entry with the content from the linked one, I get the following message
Property "Craft\EntryModel.seo" is not defined.
So my question is, how can I correctly set the seo
field on the entry being saved?
Below you can see the code currently in my plugins init
function.
craft()->on('entries.onBeforeSaveEntry', function(Event $event) {
$entry = $event->params['entry'];
if($entry->type['handle'] === 'service'){
$serviceContent = $entry->linkToService->first();
$event->params['entry']->seo = $serviceContent->seo;
// Tried this aswell, gives second error mentioned below
$entry->getContent()->seo = $serviceContent->seo;
}
);
After trying the answer provided by @justussimon91, the error message changed to:
Property "Craft\SproutSeo_MetadataModel.metadata" is not defined.
Now this might be related to something specific with the Sprout SEO plugin so I'll raise the issue there as well.