feat: instant preview of edited email template

This commit is contained in:
Björn Fromme committed 2026-08-17 12:17:05 +02:00
1 parent 489aafed3e
commit 0e1df6da7c
12 files changed
+250 -58

No files matched your search

+27 -6
View File
@@ -43,9 +43,30 @@ class EmailTextRenderer
$definition = $this->catalog->get($key);
$emailText = $this->emailTextRepository->findByKey($key);
$subject = $emailText?->getSubject() ?: $definition->defaultSubject;
$headline = $emailText?->getHeadline() ?? $definition->defaultHeadline;
$body = $emailText?->getBody() ?: $definition->defaultBody;
return $this->renderValues(
$key,
$emailText?->getSubject() ?: $definition->defaultSubject,
$emailText?->getHeadline() ?? $definition->defaultHeadline,
$emailText?->getBody() ?: $definition->defaultBody,
$placeholders
);
}
/**
* Renders wording that is not (or not yet) the saved one - the admin preview shows
* what is currently in the form, which is the whole point of previewing before saving.
* The values come straight from a half-filled form, so all three may be null.
*
* @param array<string, string|int|null> $placeholders
*/
public function renderValues(
EmailTextKey $key,
?string $subject,
?string $headline,
?string $body,
array $placeholders,
): RenderedEmailTextDto {
$definition = $this->catalog->get($key);
// Two token maps from the same values: the subject of a mail is plain text, the
// body is HTML. Escaping happens here, before substitution, so that neither the
@@ -63,9 +84,9 @@ class EmailTextRenderer
}
return new RenderedEmailTextDto(
strtr($subject, $plainTokens),
$this->prepare($headline, $htmlTokens),
$this->renderBody($body, $htmlTokens),
strtr($subject ?? '', $plainTokens),
$this->prepare($headline ?? '', $htmlTokens),
$this->renderBody($body ?? '', $htmlTokens),
);
}