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:
parent
76868079ac
commit
2d55ea78f1
24 changed files with 1058 additions and 3 deletions
36
modules/opd_daily_emails/src/Ctas.php
Normal file
36
modules/opd_daily_emails/src/Ctas.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
14
modules/opd_daily_emails/src/DailyEmail.php
Normal file
14
modules/opd_daily_emails/src/DailyEmail.php
Normal 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';
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue