Refactor talks to keep existing tests passing

References #78
This commit is contained in:
Oliver Davies 2020-05-29 21:48:45 +01:00
parent 165b6e8195
commit fafe64dac7
2 changed files with 14 additions and 10 deletions

View file

@ -0,0 +1,33 @@
<?php
namespace Drupal\custom\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 {
/**
* Find the date for the latest event.
*
* @return string|null
*/
public function findLatestEventDate(): ?string {
return Collection::make($this->get('field_events')->referencedEntities())
->map(fn(ParagraphInterface $event) => $event->get('field_date')
->getString())
->max();
}
}