API Allow risky "to" recipient fields to be configured

Fixes #333
This commit is contained in:
Damian Mooyman 2016-07-14 18:30:09 +12:00
parent 6aeca36c32
commit 255ded1542
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

View File

@ -39,6 +39,17 @@ class UserDefinedForm_EmailRecipient extends DataObject {
'EmailFrom'
);
/**
* Setting this to true will allow you to select "risky" fields as
* email recipient, such as free-text entry fields.
*
* It's advisable to leave this off.
*
* @config
* @var bool
*/
private static $allow_unbound_recipient_fields = false;
public function summaryFields() {
$fields = parent::summaryFields();
if(isset($fields['EmailAddress'])) {
@ -132,8 +143,16 @@ class UserDefinedForm_EmailRecipient extends DataObject {
);
$validSubjectFields->merge($multiOptionFields);
// To address cannot be unbound, so restrict to pre-defined lists
$validEmailToFields = $multiOptionFields;
// Check valid email-recipient fields
if($this->config()->allow_unbound_recipient_fields) {
// To address can only be email fields or multi option fields
$validEmailToFields = ArrayList::create($validEmailFromFields->toArray());
$validEmailToFields->merge($multiOptionFields);
} else {
// To address cannot be unbound, so restrict to pre-defined lists
$validEmailToFields = $multiOptionFields;
}
// Build fieldlist
$fields = FieldList::create(Tabset::create('Root')->addExtraClass('EmailRecipientForm'));