Thank you! So the hook works, also when feeding back the result into the calendar field. It also immediately updates the sorting of the pages field, just as I inteded. Here’s the final hook code:
'page.update:after' => function ($page) {
if($page->is('projects')) {
// sort pages in the calendar pages field
$calPages = [];
foreach ($page->calendar()->toPages()->sortBy('title', 'asc') as $p) {
$calPages[] = $p->id();
}
$page->update(['calendar' => yaml::encode($calPages)]);
}
}
Thank you! For me it works, but I can only see the correct sorting once I reload the page… Is there a way to push the sorted list of pages back to the panel for the correct view?