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 22, 2024
1 parent a8df472 commit 5e315a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
12 changes: 7 additions & 5 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 Expand Up @@ -660,7 +662,7 @@ function (){
// 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 .= <<<EOS
$('.step-button-wrapper[data-for="{$id}"]').addClass('hide');
Expand Down
4 changes: 2 additions & 2 deletions code/FormField/UserFormsCheckboxSetField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class UserFormsCheckboxSetField extends CheckboxSetField
{

/**
* If your project uses a custom UserFormsCheckboxSetField.ss, ensure that it includes
* If your project uses a custom UserFormsCheckboxSetField template, ensure that it includes
* `$Top.getValidationAttributesHTML().RAW` so that custom validation messages work
* For further details see
* templates/SilverStripe/UserForms/FormField/UserFormsCheckboxSetField.ss
* templates/SilverStripe/UserForms/FormField/UserFormsCheckboxSetField template
*
* Use on a template with .RAW - single and double quoted strings will be safely escaped
*
Expand Down
4 changes: 2 additions & 2 deletions code/FormField/UserFormsOptionSetField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class UserFormsOptionSetField extends OptionsetField
{

/**
* If your project uses a custom UserFormsCheckboxSetField.ss, ensure that it includes
* If your project uses a custom UserFormsCheckboxSetField template, ensure that it includes
* `$Top.getValidationAttributesHTML().RAW` so that custom validation messages work
* For further details see
* templates/SilverStripe/UserForms/FormField/UserFormsCheckboxSetField.ss
* templates/SilverStripe/UserForms/FormField/UserFormsCheckboxSetField template
*
* Use on a template with .RAW - single and double quoted strings will be safely escaped
*
Expand Down
8 changes: 7 additions & 1 deletion code/Model/Recipient/EmailRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class EmailRecipient extends DataObject
*/
private static $allow_unbound_recipient_fields = false;

/**
* The regex used to find template files for rendering emails.
* By default this finds ss template files.
*/
private static string $email_template_regex = '/^.*\.ss$/';

public function requireDefaultRecords()
{
parent::requireDefaultRecords();
Expand Down Expand Up @@ -562,7 +568,7 @@ public function getEmailTemplateDropdownValues()
$templates = [];

$finder = new FileFinder();
$finder->setOption('name_regex', '/^.*\.ss$/');
$finder->setOption('name_regex', static::config()->get('email_template_regex'));

$parent = $this->getFormParent();

Expand Down

0 comments on commit 5e315a1

Please sign in to comment.