oliverdavies.uk/modules/opd_presentations/src/Repository/PresentationNodeRepository.php
2025-06-21 00:43:11 +01:00

40 lines
1 KiB
PHP

<?php
declare(strict_types=1);
namespace Drupal\opd_presentations\Repository;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\node\NodeInterface;
use Drupal\node\NodeStorageInterface;
use Drupal\opd_presentations\Presentation;
final class PresentationNodeRepository implements PresentationRepositoryInterface {
private NodeStorageInterface $nodeStorage;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->nodeStorage = $entityTypeManager->getStorage('node');
}
public function getPublished(): array {
$query = $this->query();
$query->condition('status', NodeInterface::PUBLISHED);
$nodeIds = $query->execute();
assert(is_array($nodeIds));
/** @var Presentation[] */
return $this->nodeStorage->loadMultiple($nodeIds);
}
private function query(): QueryInterface {
$query = $this->nodeStorage->getQuery();
$query->accessCheck();
$query->condition('type', Presentation::NODE_TYPE);
return $query;
}
}