Add query condition for status

References #344
This commit is contained in:
Oliver Davies 2021-01-13 08:52:51 +00:00
parent dee6051cd9
commit 661c26dcec

View file

@ -7,6 +7,7 @@ namespace Drupal\opdavies_blog\Repository;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\node\NodeInterface;
use Drupal\opdavies_blog\Entity\Node\Post; use Drupal\opdavies_blog\Entity\Node\Post;
use Drupal\taxonomy\TermInterface; use Drupal\taxonomy\TermInterface;
use Tightenco\Collect\Support\Collection; use Tightenco\Collect\Support\Collection;
@ -49,6 +50,8 @@ final class RelatedPostsRepository {
// Only return posts with the same tags. // Only return posts with the same tags.
$query->condition('field_tags', $tagIds->toArray(), 'IN'); $query->condition('field_tags', $tagIds->toArray(), 'IN');
$query->condition('status', NodeInterface::PUBLISHED);
return $query; return $query;
} }