I have an event subscriber that contains two lifecycle event methods: prePersist and preUpdate. PrePersist works as expected - I modify the document and the changes are reflected later when I retrieve the document. However, preUpdate does not work as expected. Here's basically what it looks like:
public function preUpdate(LifecycleEventArgs $args)
{
$document = $args->getDocument();
if ($document instanceof BarProfile) {
$document->setFooCode('Salamanders');
}
}
If I create a document and set its fooCode to "placeholder" in the perPersist function, then when I get the document later, fooCode will be "placeholder". If I then update it and load it again, then I expect its fooCode to be βSalamandersβ. However, it is still a placeholder. I even tried adding error_log()material there , and it writes the material to the logs, so I see that this method is being executed.
Is there a second step that I have to do after $document->setFooCode()to create a new fooCode value?
source
share