4k: Sort articles before returning

This commit is contained in:
Oliver Davies 2020-11-14 09:44:03 +00:00
parent 91f7d094e7
commit 290c8fbcba

View file

@ -14,10 +14,20 @@ class ArticleRepository {
}
public function getAll(): array {
return $this->nodeStorage->loadByProperties([
$articles = $this->nodeStorage->loadByProperties([
'status' => NodeInterface::PUBLISHED,
'type' => 'article',
]);
$this->sortByCreatedDate($articles);
return $articles;
}
private function sortByCreatedDate(array &$articles): void {
uasort($articles, function (NodeInterface $a, NodeInterface $b): bool {
return $a->getCreatedTime() < $b->getCreatedTime();
});
}
}