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

36 lines
806 B
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;
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 getAll(bool $publishedOnly = FALSE): Collection {
$properties = ['type' => 'talk'];
if ($publishedOnly) {
$properties['status'] = TRUE;
}
return new Collection(
$this->nodeStorage->loadByProperties($properties)
);
}
}