I have a sortable pages section and I need pages to be added to the top of when they are published. I thought is would work, but I get "Call to a member function isListed() on null"
'hooks' => [
'page.changeStatus:after' => function ($page) {
if (!$page->isListed()) {
$page->sort(1);
}
}
]
cheers, it now works and changes the newly published page to have a sort order of 1. Is there a method to update all the other pages sort index otherwise they will all have the same sort order?
'hooks' => [
'page.changeStatus:after' => function ($newPage,$oldPage) {
if (!$oldPage->isListed()) {
$newPage->changeSort(1);
}
}
]