Refactor to use a short function
This commit is contained in:
parent
59f85f02d5
commit
b77c301d8c
|
@ -8,6 +8,7 @@ use Carbon\Carbon;
|
||||||
use Drupal\Core\Entity\EntityStorageInterface;
|
use Drupal\Core\Entity\EntityStorageInterface;
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||||
use Drupal\node\NodeInterface;
|
use Drupal\node\NodeInterface;
|
||||||
|
use Drupal\opdavies_talks\Entity\Node\Talk;
|
||||||
use Drupal\paragraphs\ParagraphInterface;
|
use Drupal\paragraphs\ParagraphInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ final class TalkCounter {
|
||||||
$today = Carbon::today()->format('Y-m-d H:i:s');
|
$today = Carbon::today()->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
return $this->getTalks()
|
return $this->getTalks()
|
||||||
->flatMap->getEvents()
|
->flatMap(fn(Talk $talk) => $talk->getEvents())
|
||||||
->filter(fn(ParagraphInterface $event) => $event->get('field_date')->getString() <= $today)
|
->filter(fn(ParagraphInterface $event) => $event->get('field_date')->getString() <= $today)
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue