Pre-populate the next podcast episode number

This commit is contained in:
Oliver Davies 2025-07-13 01:12:40 +01:00
parent 7a4c0223f9
commit 6b54631f46
5 changed files with 72 additions and 1 deletions

View file

@ -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;
}
}

View 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);
}
}