mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
Merge branch '6.0' into 6
This commit is contained in:
commit
8e59783356
@ -433,15 +433,17 @@ JS
|
|||||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
|
||||||
|
|
||||||
if ($submittedFormField && $submittedFormField->Value && is_string($submittedFormField->Value)) {
|
if ($submittedFormField && $submittedFormField->Value && is_string($submittedFormField->Value)) {
|
||||||
$email->setReplyTo(explode(',', $submittedFormField->Value ?? ''));
|
$emailSendTo = $this->validEmailsToArray($submittedFormField->Value);
|
||||||
|
$email->addReplyTo(...$emailSendTo);
|
||||||
}
|
}
|
||||||
} elseif ($recipient->EmailReplyTo) {
|
} elseif ($recipient->EmailReplyTo) {
|
||||||
$email->setReplyTo(explode(',', $recipient->EmailReplyTo ?? ''));
|
$emailReplyTo = $this->validEmailsToArray($recipient->EmailReplyTo);
|
||||||
|
$email->addReplyTo(...$emailReplyTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for a specified from; otherwise fall back to server defaults
|
// check for a specified from; otherwise fall back to server defaults
|
||||||
if ($recipient->EmailFrom) {
|
if ($recipient->EmailFrom) {
|
||||||
$email->setFrom(explode(',', $recipient->EmailFrom ?? ''));
|
$email->setFrom($this->validEmailsToArray($recipient->EmailFrom));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
||||||
@ -452,12 +454,12 @@ JS
|
|||||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
||||||
|
|
||||||
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
||||||
$email->setTo(explode(',', $submittedFormField->Value ?? ''));
|
$email->setTo($this->validEmailsToArray($submittedFormField->Value));
|
||||||
} else {
|
} else {
|
||||||
$email->setTo(explode(',', $recipient->EmailAddress ?? ''));
|
$email->setTo($this->validEmailsToArray($recipient->EmailAddress));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$email->setTo(explode(',', $recipient->EmailAddress ?? ''));
|
$email->setTo($this->validEmailsToArray($recipient->EmailAddress));
|
||||||
}
|
}
|
||||||
} catch (Swift_RfcComplianceException $e) {
|
} catch (Swift_RfcComplianceException $e) {
|
||||||
// The sending address is empty and/or invalid. Log and skip sending.
|
// The sending address is empty and/or invalid. Log and skip sending.
|
||||||
@ -672,4 +674,21 @@ EOS;
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check validity of email and return array of valid emails
|
||||||
|
*/
|
||||||
|
private function validEmailsToArray(?string $emails): array
|
||||||
|
{
|
||||||
|
$emailsArray = [];
|
||||||
|
$emails = explode(',', $emails ?? '');
|
||||||
|
foreach ($emails as $email) {
|
||||||
|
$email = trim($email);
|
||||||
|
if (Email::is_valid_address($email)) {
|
||||||
|
$emailsArray[] = $email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $emailsArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,14 +185,16 @@ trait UserForm
|
|||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function ($fields) {
|
||||||
|
|
||||||
// remove
|
// remove
|
||||||
$fields->removeByName('OnCompleteMessageLabel');
|
$fields->removeByName([
|
||||||
$fields->removeByName('OnCompleteMessage');
|
'OnCompleteMessageLabel',
|
||||||
$fields->removeByName('Fields');
|
'OnCompleteMessage',
|
||||||
$fields->removeByName('EmailRecipients');
|
'Fields',
|
||||||
|
'EmailRecipients'
|
||||||
|
]);
|
||||||
|
|
||||||
// define tabs
|
// define tabs
|
||||||
$fields->findOrMakeTab('Root.FormOptions', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CONFIGURATION', 'Configuration'));
|
$fields->findOrMakeTab('Root.FormOptions')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CONFIGURATION', 'Configuration'));
|
||||||
$fields->findOrMakeTab('Root.Recipients', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.RECIPIENTS', 'Recipients'));
|
$fields->findOrMakeTab('Root.Recipients')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.RECIPIENTS', 'Recipients'));
|
||||||
|
|
||||||
|
|
||||||
// text to show on complete
|
// text to show on complete
|
||||||
@ -237,7 +239,7 @@ trait UserForm
|
|||||||
$fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions());
|
$fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions());
|
||||||
|
|
||||||
$submissions = $this->getSubmissionsGridField();
|
$submissions = $this->getSubmissionsGridField();
|
||||||
$fields->findOrMakeTab('Root.Submissions', _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
$fields->findOrMakeTab('Root.Submissions')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
||||||
$fields->addFieldToTab('Root.Submissions', $submissions);
|
$fields->addFieldToTab('Root.Submissions', $submissions);
|
||||||
$fields->addFieldToTab(
|
$fields->addFieldToTab(
|
||||||
'Root.FormOptions',
|
'Root.FormOptions',
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\UserForms\Tests\Control;
|
namespace SilverStripe\UserForms\Tests\Control;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
use SilverStripe\Assets\Dev\TestAssetStore;
|
use SilverStripe\Assets\Dev\TestAssetStore;
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
use SilverStripe\Assets\Folder;
|
use SilverStripe\Assets\Folder;
|
||||||
@ -580,4 +581,36 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
$controller = new SizeStringTestableController(); // extends UserDefinedFormController
|
$controller = new SizeStringTestableController(); // extends UserDefinedFormController
|
||||||
$controller->convertSizeStringToBytes($input);
|
$controller->convertSizeStringToBytes($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function provideValidEmailsToArray()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[[], [null]],
|
||||||
|
[[], [' , , ']],
|
||||||
|
[[], ['broken.email, broken@.email, broken2.@email']],
|
||||||
|
[
|
||||||
|
['broken@email', 'correctemail@email.com'],
|
||||||
|
[', broken@email, email@-email.com,correctemail@email.com,']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['correctemail1@email.com', 'correctemail2@email.com', 'correctemail3@email.com'],
|
||||||
|
['correctemail1@email.com, correctemail2@email.com, correctemail3@email.com']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideValidEmailsToArray
|
||||||
|
* Test that provided email is valid
|
||||||
|
*/
|
||||||
|
public function testValidEmailsToArray(array $expectedOutput, array $input)
|
||||||
|
{
|
||||||
|
$class = new ReflectionClass(UserDefinedFormController::class);
|
||||||
|
$method = $class->getMethod('validEmailsToArray');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$controller = new UserDefinedFormController();
|
||||||
|
|
||||||
|
$this->assertEquals($expectedOutput, $method->invokeArgs($controller, $input));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user