diff --git a/modules/opd_presentations/opd_presentations.services.yml b/modules/opd_presentations/opd_presentations.services.yml index bacc8f79c..15f161ce8 100644 --- a/modules/opd_presentations/opd_presentations.services.yml +++ b/modules/opd_presentations/opd_presentations.services.yml @@ -1,3 +1,6 @@ services: Drupal\opd_presentations\PresentationCounter: autowire: true + Drupal\opd_presentations\Repository\PresentationNodeRepository: + autowire: true + Drupal\opd_presentations\Repository\PresentationRepositoryInterface: '@Drupal\opd_presentations\Repository\PresentationNodeRepository' diff --git a/modules/opd_presentations/src/PresentationCounter.php b/modules/opd_presentations/src/PresentationCounter.php index 6d7753c46..2e7a176b3 100644 --- a/modules/opd_presentations/src/PresentationCounter.php +++ b/modules/opd_presentations/src/PresentationCounter.php @@ -4,26 +4,15 @@ declare(strict_types=1); namespace Drupal\opd_presentations; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\node\NodeInterface; +use Drupal\opd_presentations\Repository\PresentationRepositoryInterface; final class PresentationCounter { - public function __construct(private EntityTypeManagerInterface $entityTypeManager) { + public function __construct(private PresentationRepositoryInterface $presentationRepository) { } public function getPastCount(): int { - $nodeStorage = $this->entityTypeManager->getStorage('node'); - - $query = $nodeStorage->getQuery(); - $query->condition('status', NodeInterface::PUBLISHED); - $query->condition('type', Presentation::NODE_TYPE); - $query->accessCheck(); - - $nodeIds = $query->execute(); - - /** @var Presentation[] */ - $presentations = $nodeStorage->loadMultiple($nodeIds); + $presentations = $this->presentationRepository->getPublished(); return array_reduce( array: $presentations, diff --git a/modules/opd_presentations/src/Repository/PresentationNodeRepository.php b/modules/opd_presentations/src/Repository/PresentationNodeRepository.php new file mode 100644 index 000000000..8cf4ef3bd --- /dev/null +++ b/modules/opd_presentations/src/Repository/PresentationNodeRepository.php @@ -0,0 +1,29 @@ +entityTypeManager->getStorage('node'); + + $query = $nodeStorage->getQuery(); + $query->accessCheck(); + $query->condition('status', NodeInterface::PUBLISHED); + $query->condition('type', Presentation::NODE_TYPE); + + $nodeIds = $query->execute(); + + return $nodeStorage->loadMultiple($nodeIds); + } + +} diff --git a/modules/opd_presentations/src/Repository/PresentationRepositoryInterface.php b/modules/opd_presentations/src/Repository/PresentationRepositoryInterface.php new file mode 100644 index 000000000..4666317fb --- /dev/null +++ b/modules/opd_presentations/src/Repository/PresentationRepositoryInterface.php @@ -0,0 +1,14 @@ +