- Rename `opdavies_blog` to `blog`. - Rename `opdavies_blog_test` to `blog_test`. - Rename `opdavies_talks` to `talks`. - Rename `opdavies_talks_test` to `talks_test`. The files within the directories haven't changed, so there is no breaking change caused by renaming the directories. Please enter the commit message for your changes. Lines starting
57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Drupal\opdavies_talks\Entity\Node;
|
|
|
|
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
|
|
use Drupal\node\Entity\Node;
|
|
use Drupal\paragraphs\ParagraphInterface;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* Defines an talk node class.
|
|
*
|
|
* @ContentEntityBundleClass(
|
|
* label = @Translation("Talk"),
|
|
* entity_type = "node",
|
|
* bundle = "talk"
|
|
* );
|
|
*/
|
|
class Talk extends Node implements ContentEntityBundleInterface {
|
|
|
|
public function addEvent(ParagraphInterface $event): void {
|
|
$this->set(
|
|
'field_events',
|
|
$this->getEvents()->push($event)->toArray()
|
|
);
|
|
}
|
|
|
|
public function getEvents(): Collection {
|
|
return Collection::make($this->get('field_events')
|
|
->referencedEntities());
|
|
}
|
|
|
|
public function getNextDate(): ?int {
|
|
if ($this->get('field_event_date')->isEmpty()) {
|
|
return NULL;
|
|
}
|
|
|
|
return (int) $this->get('field_event_date')->getString();
|
|
}
|
|
|
|
/**
|
|
* Find the date for the latest event.
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public function findLatestEventDate(): ?string {
|
|
return $this->getEvents()
|
|
->map(fn(ParagraphInterface $event) => $event->get('field_date')
|
|
->getString())
|
|
->max();
|
|
}
|
|
|
|
public function setNextDate(int $date): void {
|
|
$this->set('field_event_date', $date);
|
|
}
|
|
|
|
}
|