How can I set a page to be the first after having be created ? Without using the flip trick as I need to be able to use drag&drop sorting.
I tried this but it doesn’t work :
'page.create:after' => function ($page) {
if ($page->intendedTemplate() == 'project') {
$page->sort(1);
}
}
Thank you !
texnixe
January 30, 2020, 12:47pm
2
Since the page is created as a draft, you have to change the status first (changeStatus()
) then sort.
I already tried this and actually I already have a code above this one that sets all pages to listed :
'page.create:after' => function ($page) {
if ($page->intendedTemplate() != 'vimeo.video') {
$page->changeStatus('listed');
}
if ($page->intendedTemplate() == 'project') {
$page->sort(1);
}
}
Maybe the sorting/changeStatus is asynchronous ?
If you do it like this, you first have to store the new page in a new variable, then apply sorting:
$newPage = $page->changeStatus('listed');
...
$newPage->sort(1);
1 Like
Great thanks ! Didn’t know that.
It works
That is because these methods do not mutate the objects themselves but return a modified object which you have to store in a new variable to be able to work with it.