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

@ -0,0 +1,57 @@
<?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);
}
}