From 661c26dcec285c9080875153517adb5310ce2e9d Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 13 Jan 2021 08:52:51 +0000 Subject: [PATCH] Add query condition for status References #344 --- .../custom/blog/src/Repository/RelatedPostsRepository.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/modules/custom/blog/src/Repository/RelatedPostsRepository.php b/web/modules/custom/blog/src/Repository/RelatedPostsRepository.php index e89e754..ccdb203 100644 --- a/web/modules/custom/blog/src/Repository/RelatedPostsRepository.php +++ b/web/modules/custom/blog/src/Repository/RelatedPostsRepository.php @@ -7,6 +7,7 @@ namespace Drupal\opdavies_blog\Repository; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\Query\QueryInterface; +use Drupal\node\NodeInterface; use Drupal\opdavies_blog\Entity\Node\Post; use Drupal\taxonomy\TermInterface; use Tightenco\Collect\Support\Collection; @@ -49,6 +50,8 @@ final class RelatedPostsRepository { // Only return posts with the same tags. $query->condition('field_tags', $tagIds->toArray(), 'IN'); + $query->condition('status', NodeInterface::PUBLISHED); + return $query; }