mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
Merge branch '5.4'
This commit is contained in:
commit
4d39c83ee9
@ -2,13 +2,16 @@
|
||||
|
||||
namespace SilverStripe\UserForms\Control;
|
||||
|
||||
use Exception;
|
||||
use PageController;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Upload;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Email\Email;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\i18n\i18n;
|
||||
@ -23,6 +26,7 @@ use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use Swift_RfcComplianceException;
|
||||
|
||||
/**
|
||||
* Controller for the {@link UserDefinedForm} page type.
|
||||
@ -350,16 +354,30 @@ JS
|
||||
|
||||
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
||||
$emailTo = $recipient->SendEmailToField();
|
||||
if ($emailTo && $emailTo->exists()) {
|
||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
||||
|
||||
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
||||
$email->setTo(explode(',', $submittedFormField->Value));
|
||||
try {
|
||||
if ($emailTo && $emailTo->exists()) {
|
||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
||||
|
||||
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
||||
$email->setTo(explode(',', $submittedFormField->Value));
|
||||
} else {
|
||||
$email->setTo(explode(',', $recipient->EmailAddress));
|
||||
}
|
||||
} else {
|
||||
$email->setTo(explode(',', $recipient->EmailAddress));
|
||||
}
|
||||
} else {
|
||||
$email->setTo(explode(',', $recipient->EmailAddress));
|
||||
} catch (Swift_RfcComplianceException $e) {
|
||||
// The sending address is empty and/or invalid. Log and skip sending.
|
||||
$error = sprintf(
|
||||
'Failed to set sender for userform submission %s: %s',
|
||||
$submittedForm->ID,
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
Injector::inst()->get(LoggerInterface::class)->notice($error);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// check to see if there is a dynamic subject
|
||||
|
@ -103,7 +103,7 @@ class UserFormFieldEditorExtension extends DataExtension
|
||||
new GridFieldDeleteAction(),
|
||||
new GridFieldToolbarHeader(),
|
||||
new GridFieldOrderableRows('Sort'),
|
||||
new GridFieldDetailForm()
|
||||
new GridFieldDetailForm(null, false, false)
|
||||
);
|
||||
|
||||
$editButton->removeExtraClass('grid-field__icon-action--hidden-on-hover');
|
||||
|
@ -84,7 +84,7 @@ class EditableCountryDropdownField extends EditableFormField
|
||||
|
||||
public function getValueFromData($data)
|
||||
{
|
||||
if (isset($data[$this->Name])) {
|
||||
if (!empty($data[$this->Name])) {
|
||||
$source = $this->getFormField()->getSource();
|
||||
return $source[$data[$this->Name]];
|
||||
}
|
||||
|
@ -550,6 +550,12 @@ class EmailRecipient extends DataObject
|
||||
if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
|
||||
$result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
|
||||
}
|
||||
|
||||
// Sending will also fail if there's no recipient defined
|
||||
if (!$this->EmailAddress && !$this->SendEmailToFieldID) {
|
||||
$result->addError(_t(__CLASS__.".EMAILTOREQUIRED", '"Send email to" address or field is required'));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ SQL;
|
||||
$config->addComponent(new GridFieldDeleteAction());
|
||||
$config->addComponent(new GridFieldPageCount('toolbar-header-right'));
|
||||
$config->addComponent($pagination = new GridFieldPaginator(25));
|
||||
$config->addComponent(new GridFieldDetailForm());
|
||||
$config->addComponent(new GridFieldDetailForm(null, null, false));
|
||||
$config->addComponent(new GridFieldButtonRow('after'));
|
||||
$config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
|
||||
$config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
|
||||
|
@ -35,7 +35,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-preset-es2016": "^6.24.1",
|
||||
"jquery": "^3.2.1",
|
||||
"jquery": "^3.4.0",
|
||||
"mime": "^1.4.1"
|
||||
},
|
||||
"babel": {
|
||||
|
@ -27,4 +27,15 @@ class EmailRecipientTest extends SapphireTest
|
||||
$result = $recipient->getEmailBodyContent();
|
||||
$this->assertContains('/about-us/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException SilverStripe\ORM\ValidationException
|
||||
* @expectedExceptionMessage "Send email to" address or field is required
|
||||
*/
|
||||
public function testEmptyRecipientFailsValidation()
|
||||
{
|
||||
$recipient = new EmailRecipient();
|
||||
$recipient->EmailFrom = 'test@example.com';
|
||||
$recipient->write();
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$this->assertNotContains('SummaryHide', array_keys($summaryFields), 'Summary field showing displayed field');
|
||||
}
|
||||
|
||||
|
||||
public function testEmailRecipientPopup()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
@ -114,6 +113,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$popup = new EmailRecipient();
|
||||
$popup->FormID = $form->ID;
|
||||
$popup->FormClass = UserDefinedForm::class;
|
||||
$popup->EmailAddress = 'test@example.com';
|
||||
|
||||
$fields = $popup->getCMSFields();
|
||||
|
||||
@ -146,6 +146,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
public function testGetEmailBodyContent()
|
||||
{
|
||||
$recipient = new EmailRecipient();
|
||||
$recipient->EmailAddress = 'test@example.com';
|
||||
|
||||
$emailBody = 'not html';
|
||||
$emailBodyHtml = '<p>html</p>';
|
||||
@ -185,6 +186,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$recipient = new EmailRecipient();
|
||||
$recipient->FormID = $page->ID;
|
||||
$recipient->FormClass = UserDefinedForm::class;
|
||||
$recipient->EmailAddress = 'test@example.com';
|
||||
|
||||
// Set the default template
|
||||
$recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues()));
|
||||
|
@ -3160,9 +3160,9 @@ isstream@~0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
|
||||
|
||||
jquery@^3.2.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.2.1.tgz#5c4d9de652af6cd0a770154a631bba12b015c787"
|
||||
jquery@^3.4.0:
|
||||
version "3.4.1"
|
||||
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2"
|
||||
|
||||
js-base64@^2.1.8, js-base64@^2.1.9:
|
||||
version "2.5.1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user