Skip to content

Commit

Permalink
ENH Update code to reflect changes in template layer
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Oct 14, 2024
1 parent 81cba4e commit 80112d7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions code/Control/UserDefinedFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
use SilverStripe\Versioned\Versioned;
use SilverStripe\Model\ArrayData;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;
use SilverStripe\Model\ModelData;
use SilverStripe\View\TemplateEngine;
use SilverStripe\View\ViewLayerData;
use Swift_RfcComplianceException;

/**
Expand Down Expand Up @@ -421,7 +422,8 @@ public function process($data, $form)
// Include any parsed merge field references from the CMS editor - this is already escaped
// This string substitution works for both HTML and plain text emails.
// $recipient->getEmailBodyContent() will retrieve the relevant version of the email
$emailData['Body'] = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
$engine = Injector::inst()->create(TemplateEngine::class);
$emailData['Body'] = $engine->renderString($recipient->getEmailBodyContent(), ViewLayerData::create($mergeFields));
// only include visible fields if recipient visibility flag is set
if ((bool) $recipient->HideInvisibleFields) {
$emailData['Fields'] = $visibleSubmittedFields;
Expand Down Expand Up @@ -487,10 +489,10 @@ public function process($data, $form)
if ($submittedFormField && trim($submittedFormField->Value ?? '')) {
$email->setSubject($submittedFormField->Value);
} else {
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
$email->setSubject($engine->renderString($recipient->EmailSubject, ViewLayerData::create($mergeFields)));
}
} else {
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
$email->setSubject($engine->renderString($recipient->EmailSubject, ViewLayerData::create($mergeFields)));
}

$this->extend('updateEmail', $email, $recipient, $emailData);
Expand Down

0 comments on commit 80112d7

Please sign in to comment.