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

51 lines
1.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;
2020-09-04 20:49:23 +01:00
use Drupal\opdavies_talks\Entity\Node\Talk;
2020-12-17 23:25:59 +00:00
use Tightenco\Collect\Support\Collection;
2020-08-21 12:00:00 +01:00
final class TalkRepository {
private EntityStorageInterface $nodeStorage;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->nodeStorage = $entityTypeManager->getStorage('node');
}
/**
* @return Collection|Talk[]
*/
public function findAll(): Collection {
$talks = $this->nodeStorage->loadByProperties($this->defaultProperties());
2020-08-21 12:00:00 +01:00
return new Collection($talks);
2020-08-21 12:00:00 +01:00
}
/**
* @return Collection|Talk[]
*/
public function findAllPublished(): Collection {
$talks = $this->nodeStorage->loadByProperties(array_merge(
$this->defaultProperties(),
[
'status' => NodeInterface::PUBLISHED,
],
));
return new Collection($talks);
}
private function defaultProperties(): array {
return [
'type' => 'talk',
];
}
2020-08-21 12:00:00 +01:00
}