Add CTAs to daily emails

Add a daily email CTA node type and reference field to attach a CTA to a
daily email.

Also update the RSS feed view to include the referenced body field
value.
This commit is contained in:
Oliver Davies 2025-06-13 11:14:11 +01:00
parent 76868079ac
commit 2d55ea78f1
24 changed files with 1058 additions and 3 deletions

View file

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Drupal\opd_daily_emails;
use Drupal\node\NodeInterface;
use Webmozart\Assert\Assert;
final class Ctas {
public function isEmpty(): bool {
return empty($this->ctas);
}
public function getRandomCta(): NodeInterface {
return $this->ctas[array_rand($this->ctas)];
}
/**
* @param list<NodeInterface> $nodes
*/
public static function fromNodes(array $nodes): self {
return new self($nodes);
}
/**
* @param list<NodeInterface> $ctas
*/
private function __construct(
private array $ctas,
) {
Assert::allIsInstanceOf($ctas, NodeInterface::class);
}
}

View file

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Drupal\opd_daily_emails;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
final class DailyEmail extends Node implements NodeInterface {
public const NODE_TYPE = 'daily_email';
}