oliverdavies.uk/web/modules/custom/talks/src/Repository/TalkRepository.php

44 lines
1 KiB
PHP
Raw Normal View History

2020-08-21 12:00:00 +01:00
<?php
declare(strict_types=1);
namespace Drupal\opdavies_talks\Repository;
2020-08-21 12:00:00 +01:00
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
use Drupal\opdavies_talks\Collection\TalkCollection;
2020-08-21 12:00:00 +01:00
final class TalkRepository {
private EntityStorageInterface $nodeStorage;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->nodeStorage = $entityTypeManager->getStorage('node');
}
public function findAll(): TalkCollection {
$talks = $this->nodeStorage->loadByProperties($this->defaultProperties());
2020-08-21 12:00:00 +01:00
return new TalkCollection($talks);
2020-08-21 12:00:00 +01:00
}
public function findAllPublished(): TalkCollection {
$talks = $this->nodeStorage->loadByProperties(array_merge(
$this->defaultProperties(),
[
'status' => NodeInterface::PUBLISHED,
],
));
return new TalkCollection($talks);
}
private function defaultProperties(): array {
return [
'type' => 'talk',
];
}
2020-08-21 12:00:00 +01:00
}