Fix PageCollection::sort() using id as default property, returning as adjacent pages in completely different places within hierarchy

This commit is contained in:
Giuseppe Criscione 2020-12-13 22:46:50 +01:00
parent 0992ff4e4f
commit ae222d2de3

View File

@ -9,6 +9,13 @@ use Formwork\Utils\Str;
class PageCollection extends Collection class PageCollection extends Collection
{ {
/**
* Default property used to sort pages
*
* @var string
*/
protected const DEFAULT_SORT_PROPERTY = 'relativePath';
/** /**
* Pagination related to the collection * Pagination related to the collection
* *
@ -111,7 +118,7 @@ class PageCollection extends Collection
* *
* @param int|string $direction Sorting direction (SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending) * @param int|string $direction Sorting direction (SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending)
*/ */
public function sort(string $property = 'id', $direction = SORT_ASC): self public function sort(string $property = self::DEFAULT_SORT_PROPERTY, $direction = SORT_ASC): self
{ {
$pageCollection = clone $this; $pageCollection = clone $this;