Merge pull request #855 from 3Dgoo/feature/subjects-with-fields

Allow form fields in email subjects
This commit is contained in:
Dylan Wagstaff 2019-01-29 12:14:54 +13:00 committed by GitHub
commit df918cac8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 8 deletions

View File

@ -364,10 +364,10 @@ JS
if ($submittedFormField && trim($submittedFormField->Value)) {
$email->setSubject($submittedFormField->Value);
} else {
$email->setSubject($recipient->EmailSubject);
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
}
} else {
$email->setSubject($recipient->EmailSubject);
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
}
$this->extend('updateEmail', $email, $recipient, $emailData);

View File

@ -11,6 +11,7 @@ use SilverStripe\Forms\FormAction;
use SilverStripe\ORM\DataObject;
use SilverStripe\UserForms\Control\UserDefinedFormController;
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
use SilverStripe\UserForms\Model\UserDefinedForm;
use SilverStripe\View\ArrayData;
@ -51,10 +52,10 @@ class UserDefinedFormControllerTest extends FunctionalTest
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
// should have a submitted form field now
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic-text-name'");
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic_text_name'");
$this->assertListAllMatch(
[
'Name' => 'basic-text-name',
'Name' => 'basic_text_name',
'Value' => 'Basic Value',
'Title' => 'Basic Text Field'
],
@ -332,4 +333,38 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
}
public function testRecipientSubjectMergeFields()
{
$form = $this->setupFormFrontend();
$recipient = $this->objFromFixture(EmailRecipient::class, 'recipient-1');
$recipient->EmailSubject = 'Email Subject: $basic_text_name';
$recipient->write();
$this->autoFollowRedirection = false;
$this->clearEmails();
// load the form
$this->get($form->URLSegment);
$field = $this->objFromFixture(EditableTextField::class, 'basic-text');
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
// should have a submitted form field now
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic_text_name'");
$this->assertListAllMatch(
[
'Name' => 'basic_text_name',
'Value' => 'Basic Value',
'Title' => 'Basic Text Field'
],
$submitted
);
// check emails
$this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject: Basic Value');
}
}

View File

@ -1,10 +1,10 @@
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
basic-text:
Name: basic-text-name
Name: basic_text_name
Title: Basic Text Field
basic-text-2:
Name: basic-text-name
Name: basic_text_name
Title: Basic Text Field
required-text:

View File

@ -63,11 +63,11 @@ SilverStripe\UserForms\Model\EditableFormField\EditableOption:
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
basic-text:
Name: basic-text-name
Name: basic_text_name
Title: Basic Text Field
basic-text-2:
Name: basic-text-name
Name: basic_text_name
Title: Basic Text Field
your-name-field: