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

@ -13,7 +13,7 @@ use Drupal\discoverable_entity_bundle_classes\Storage\Node\NodeStorage;
* Implements hook_entity_type_build(). * Implements hook_entity_type_build().
*/ */
function custom_entity_type_build(array &$entityTypes): void { function custom_entity_type_build(array &$entityTypes): void {
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entityTypes */ /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entityTypes */
if (isset($entityTypes['node'])) { if (isset($entityTypes['node'])) {
$entityTypes['node']->setStorageClass(NodeStorage::class); $entityTypes['node']->setStorageClass(NodeStorage::class);
} }

View file

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