From ae1136c56579ee0c90b1fa0aca603e1c631cb5cd Mon Sep 17 00:00:00 2001 From: Jean Spiteri Date: Fri, 27 Jun 2014 12:45:13 +0000 Subject: [PATCH] Test --- code/model/UserDefinedForm.php | 62 +++++++++++++++++----------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/code/model/UserDefinedForm.php b/code/model/UserDefinedForm.php index 9e0452c..d814fa3 100755 --- a/code/model/UserDefinedForm.php +++ b/code/model/UserDefinedForm.php @@ -977,8 +977,8 @@ JS $email->populateTemplate($emailData); $email->setFrom($recipient->EmailFrom); $email->setBody($recipient->EmailBody); - $email->setSubject($recipient->EmailSubject); $email->setTo($recipient->EmailAddress); + $email->setSubject($recipient->EmailSubject) if($recipient->EmailReplyTo) { $email->setReplyTo($recipient->EmailReplyTo); @@ -1001,6 +1001,12 @@ JS } } + // check to see if there is a dynamic subject + if($recipient->SendEmailSubjectField()) { + $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name); + $email->setSubject($submittedFormField->Value); + } + $this->extend('updateEmail', $email, $recipient, $emailData); if($recipient->SendPlain) { @@ -1100,7 +1106,8 @@ class UserDefinedForm_EmailRecipient extends DataObject { private static $has_one = array( 'Form' => 'UserDefinedForm', 'SendEmailFromField' => 'EditableFormField', - 'SendEmailToField' => 'EditableFormField' + 'SendEmailToField' => 'EditableFormField', + 'SendEmailSubjectField' => 'EditableFormField' ); private static $summary_fields = array(); @@ -1129,41 +1136,34 @@ class UserDefinedForm_EmailRecipient extends DataObject { if($this->Form()) { $dropdowns = array(); - $validEmailFields = DataObject::get("EditableEmailField", "\"ParentID\" = '" . (int)$this->FormID . "'"); $multiOptionFields = DataObject::get("EditableMultipleOptionField", "\"ParentID\" = '" . (int)$this->FormID . "'"); + $validSubjectFields = EditableTextField::get()->filter('ParentID', $this->FormID)->filterByCallback(function($item, $list) { return $item->getSetting('Rows') === 1; }); - // if they have email fields then we could send from it + $fields->insertAfter($dropdowns[] = new DropdownField( + 'SendEmailFromFieldID', + _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'), + $validEmailFields->map('ID', 'Title') + ), 'EmailReplyTo'); + + if($multiOptionFields) { + $validEmailFields = $validEmailFields->toArrayList(); + $validEmailFields->merge($multiOptionFields); + $validSubjectFields->merge($multiOptionFields); + } if($validEmailFields) { $fields->insertAfter($dropdowns[] = new DropdownField( - 'SendEmailFromFieldID', - _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'), - $validEmailFields->map('ID', 'Title') - ), 'EmailReplyTo'); - } - - // if they have multiple options - if($multiOptionFields || $validEmailFields) { - - if($multiOptionFields && $validEmailFields) { - $multiOptionFields = $multiOptionFields->toArray(); - $multiOptionFields = array_merge( - $multiOptionFields, - $validEmailFields->toArray() - ); - - $multiOptionFields = ArrayList::create($multiOptionFields); - } - else if(!$multiOptionFields) { - $multiOptionFields = $validEmailFields; - } - - $multiOptionFields = $multiOptionFields->map('ID', 'Title'); - $fields->insertAfter($dropdowns[] = new DropdownField( - 'SendEmailToFieldID', - _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'), - $multiOptionFields + 'SendEmailToFieldID', + _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'), + $validEmailFields = $validEmailFields->map('ID', 'Title'); ), 'EmailAddress'); + } + if($validSubjectFields) { + $fields->insertAfter($dropdowns[] = new DropdownField( + 'SendEmailSubjectFieldID', + _t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '... or select a field to use as the subject'), + $validSubjectFields->map('ID', 'Title') + ), 'SendEmailSubjectField'); } if($dropdowns) {