Rename and re-organise custom modules

- Rename `opd_talks` to `opdavies_talks`
- Rename `custom` to `opdavies_blog`
This commit is contained in:
Oliver Davies 2020-08-24 09:26:44 +01:00
parent e4e898f22c
commit 9b1a8fb3be
53 changed files with 125 additions and 116 deletions

View file

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
namespace Drupal\custom\Service;
use Carbon\Carbon;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\custom\Entity\Node\Talk;
use Drupal\node\NodeInterface;
use Drupal\paragraphs\ParagraphInterface;
use Illuminate\Support\Collection;
final class TalkCounter {
private EntityStorageInterface $nodeStorage;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->nodeStorage = $entityTypeManager->getStorage('node');
}
public function getCount(): int {
$today = Carbon::today()->format('Y-m-d H:i:s');
return $this->getTalks()
->flatMap->getEvents()
->filter(fn(ParagraphInterface $event) => $event->get('field_date')->getString() <= $today)
->count();
}
private function getTalks(): Collection {
$talks = $this->nodeStorage->loadByProperties([
'status' => NodeInterface::PUBLISHED,
'type' => 'talk',
]);
return new Collection($talks);
}
}