Pre-populate the next podcast episode number
This commit is contained in:
parent
7a4c0223f9
commit
6b54631f46
5 changed files with 72 additions and 1 deletions
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_podcast\Action;
|
||||
|
||||
use Drupal\opd_podcast\Repository\PodcastNodeRepository;
|
||||
|
||||
readonly final class GetNextPodcastEpisodeNumber {
|
||||
|
||||
public function __construct(private PodcastNodeRepository $repository) {
|
||||
}
|
||||
|
||||
public function __invoke(): int {
|
||||
$episodes = $this->repository->getPublished();
|
||||
|
||||
return count($episodes) + 1;
|
||||
}
|
||||
|
||||
}
|
33
modules/opd_podcast/src/Repository/PodcastNodeRepository.php
Normal file
33
modules/opd_podcast/src/Repository/PodcastNodeRepository.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_podcast\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\node\NodeStorageInterface;
|
||||
|
||||
readonly final class PodcastNodeRepository {
|
||||
|
||||
private NodeStorageInterface $nodeStorage;
|
||||
|
||||
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
|
||||
$this->nodeStorage = $entityTypeManager->getStorage('node');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<NodeInterface>
|
||||
*/
|
||||
public function getPublished(): array {
|
||||
$query = $this->nodeStorage->getQuery();
|
||||
$query->accessCheck();
|
||||
$query->condition('status', NodeInterface::PUBLISHED);
|
||||
$query->condition('type', 'podcast_episode');
|
||||
|
||||
$nodeIds = $query->execute();
|
||||
|
||||
return $this->nodeStorage->loadMultiple($nodeIds);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue