Get past events for each presentation
This commit is contained in:
parent
122f4a9bec
commit
6e19d01eed
2 changed files with 32 additions and 4 deletions
|
@ -4,13 +4,22 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\opd_presentations\Entity;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\paragraphs\Entity\Paragraph;
|
||||
|
||||
final class Presentation extends Node implements NodeInterface {
|
||||
|
||||
public function getPastEvents(): array {
|
||||
return $this->get('field_events')->referencedEntities();
|
||||
$events = $this->get('field_events')->referencedEntities();
|
||||
|
||||
$today = (new DrupalDateTime('today'))->format('U');
|
||||
|
||||
return array_filter(
|
||||
array: $events,
|
||||
callback: fn (Paragraph $event): bool => $event->get('field_date')->value < $today,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue