From dc84a231b9c439b4250cd8a72ff78c880cdf253e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Mon, 14 Oct 2024 14:44:24 +1300 Subject: [PATCH] ENH Update code to reflect changes in template layer --- code/Control/UserDefinedFormController.php | 12 +++++++----- code/FormField/UserFormsCheckboxSetField.php | 4 ++-- code/FormField/UserFormsOptionSetField.php | 4 ++-- code/Model/Recipient/EmailRecipient.php | 8 +++++++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/code/Control/UserDefinedFormController.php b/code/Control/UserDefinedFormController.php index 951c9a9..0044482 100644 --- a/code/Control/UserDefinedFormController.php +++ b/code/Control/UserDefinedFormController.php @@ -31,8 +31,9 @@ use SilverStripe\UserForms\Model\UserDefinedForm; 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; /** @@ -421,7 +422,8 @@ JS // 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; @@ -487,10 +489,10 @@ JS 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); @@ -660,7 +662,7 @@ EOS; // Hide the step jump button if the FormStep has is initially hidden. // This is particularly important beacause the next/prev page buttons logic is controlled by // the visibility of the FormStep buttons - // The HTML for the FormStep buttons is defined in UserFormProgress.ss + // The HTML for the FormStep buttons is defined in the UserFormProgress template $id = str_replace('#', '', $target ?? ''); $result .= <<setOption('name_regex', '/^.*\.ss$/'); + $finder->setOption('name_regex', static::config()->get('email_template_regex')); $parent = $this->getFormParent();