Automatically order events when a talk is saved
To ensure that the event dates for a talk are always in the correct order, and to make the editing experience easier, this change automatically re-orders the events on a talk node to be based on the event date. Fixes #74
This commit is contained in:
parent
45fda0fed1
commit
56f3434c4a
7 changed files with 190 additions and 10 deletions
|
@ -18,13 +18,25 @@ use Illuminate\Support\Collection;
|
|||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the date for the latest event.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function findLatestEventDate(): ?string {
|
||||
return Collection::make($this->get('field_events')->referencedEntities())
|
||||
return $this->getEvents()
|
||||
->map(fn(ParagraphInterface $event) => $event->get('field_date')
|
||||
->getString())
|
||||
->max();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue