Hi there!
I have created a collection of pages which include in their blueprint a hidden field called publishedStatus. It is automatically filled with predefined values after the page is updated, based on another field in the same blueprint called date.
As you can see in the hook below, if the date defined is older than 90 days, the publishedStatus is filled with ‘Old’, otherwise it is ‘New’, or upcoming, if the date is in the ‘future’.
'hooks' => [
'page.update:after' => function ($page) {
if ($page->intendedTemplate() == 'book') {
$today = new DateTime(date('Y-m-d'));
$publishedDate = new DateTime($page->date());
$interval = $today->diff($publishedDate);
if($publishedDate <= $today){
if($interval->days <= 90){
$page->update([
'publishedStatus' => 'New'
]);
} else{
$page->update([
'publishedStatus' => 'Old'
]);
}
} else {
$page->update([
'publishedStatus' => 'Upcoming'
]);
}
}
}
}
]
Everything works fine for now. However, I’d like this publishedStatus field to update automatically without having to update the page in the panel. Is there a way to automate this?
Thank you for your help 
