Rename and re-organise custom modules
- Rename `opd_talks` to `opdavies_talks` - Rename `custom` to `opdavies_blog`
This commit is contained in:
parent
e4e898f22c
commit
9b1a8fb3be
53 changed files with 125 additions and 116 deletions
57
web/modules/custom/opdavies_talks/src/Entity/Node/Talk.php
Normal file
57
web/modules/custom/opdavies_talks/src/Entity/Node/Talk.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue