Good afternoon,
so I want to automatically populate a createdOn/createdBy and a lastUpdatedOn/lastUpdatedBy fields in a page when the page is created or updated via the panel.
This works easily with the following hooks which I have put into my config.php (N.B. to everyone who tries the same as me beforehand, i.e. displaying these fields via blueprint in the panel - dont do it! It will mix up everything and it wont work or - more realistic - I made some error ):
'hooks' => [
'page.create:after' => function (Kirby\Cms\Page $page) {
$createdOn = Kirby\Toolkit\Date::now();
$user = kirby()->user();
$page->update([
'createdOn' => $createdOn,
'createdBy' => $user
]);
},
'page.update:after' => function (Kirby\Cms\Page $newPage, Kirby\Cms\Page $oldPage) {
$updatedOn = Kirby\Toolkit\Date::now();
$updatedBy = kirby()->user();
$newPage->update([
'lastUpdatedOn' => $updatedOn,
'lastUpdatedBy' => $updatedBy
]);
}
],
Now when I create a page via the Panel, the createdOn/createdBy fields are populated - wonderful! But also the lastUpdatedOn/lastUpdatedBy were, which should not be the case IHMO when creating a NEW page, right?
Am I doing something wrong or is this a bug?
Thanks
Andreas