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

@ -1,14 +1,22 @@
<?php
declare(strict_types=1);
namespace Drupal\custom\Entity\Node;
namespace Drupal\custom\Entity;
use Drupal\node\Entity\Node as CoreNode;
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
use Drupal\node\Entity\Node;
use Drupal\paragraphs\ParagraphInterface;
use Illuminate\Support\Collection;
final class Node extends CoreNode {
/**
* 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.
@ -16,10 +24,6 @@ final class Node extends CoreNode {
* @return string|null
*/
public function findLatestEventDate(): ?string {
if (!$this->hasField('field_events')) {
return NULL;
}
return Collection::make($this->get('field_events')->referencedEntities())
->map(fn(ParagraphInterface $event) => $event->get('field_date')
->getString())