What is the default $field
in the sort-by function? I could not find it. Is it sort
?
There is no default field. If you don’t pass any arguments to sortBy()
the collection is filtered in alphabetical order as in the file system.
So if I need to have it sort by panel sort order, I need to do this?
$pages->sortBy('sort');
or will the filesystem names always make the panel drag/drop sort order the same as alphabetical because of the number prefix on the page folders?
A quick test shows me that if I sort by sort
I get the invisible ones first in alphabetical order (UID) and then the visible ones sorted by sort number.
I got 3 different results:
No sorting
Visible pages first and invisible second, sorted by drag/drop order.
print_r($page->siblings());
Sort
Invisible pages first and visible second, sorted by drag/drop order.
print_r($page->siblings()->sortBy('sort'));
Unknown
A probably unknown sort value will sort them alphabetically.
print_r($page->siblings()->sortBy('asdasd'));
Conclusion
I think it’s a bit strange that it works like this. Nothing really tells us that sort
will just put invisible pages before the visible ones. Maybe it would be more natural to have a sortBy('invisible')
or something.
Then about the unknown sort order. I would expect it to fallback to an empty value, like with no sorting value (visible pages first and invisible second).
Just some thoughts on it. But now I know how it works.