Rename custom module directories
- 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
This commit is contained in:
parent
d7d5a6c8a3
commit
cbe60209e6
59 changed files with 0 additions and 0 deletions
57
web/modules/custom/talks/src/Entity/Node/Talk.php
Normal file
57
web/modules/custom/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