From 7714b20d3cc1476ccdf160e53aa06d4fa8312500 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 17 Jan 2024 10:57:40 +0000 Subject: [PATCH] Only load published nodes --- .../custom/example/src/Repository/PostNodeRepository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/modules/custom/example/src/Repository/PostNodeRepository.php b/web/modules/custom/example/src/Repository/PostNodeRepository.php index b7221fc..575312f 100644 --- a/web/modules/custom/example/src/Repository/PostNodeRepository.php +++ b/web/modules/custom/example/src/Repository/PostNodeRepository.php @@ -17,7 +17,9 @@ final class PostNodeRepository { */ public function findAll(): array { $nodeStorage = $this->entityTypeManager->getStorage('node'); - $nodes = $nodeStorage->loadMultiple(); + $nodes = $nodeStorage->loadByProperties([ + 'status' => TRUE, + ]); uasort($nodes, function (NodeInterface $a, NodeInterface $b): int { return $a->getCreatedTime() <=> $b->getCreatedTime();