Merge pull request #241 from nhorstmeier/Bugfix_196

BUGFIX set email recipient on initial write()
This commit is contained in:
Will Rossiter 2014-12-08 22:17:41 +13:00
commit 729318fc0a

View File

@ -1173,40 +1173,39 @@ class UserDefinedForm_EmailRecipient extends DataObject {
new TextareaField('EmailBody', _t('UserDefinedForm.EMAILBODY','Body')) new TextareaField('EmailBody', _t('UserDefinedForm.EMAILBODY','Body'))
); );
if($this->Form()) { $formID = ($this->FormID != 0) ? $this->FormID : Session::get('CMSMain.currentPage');
$dropdowns = array(); $dropdowns = array();
// if they have email fields then we could send from it // if they have email fields then we could send from it
$validEmailFields = EditableEmailField::get()->filter('ParentID', (int)$this->FormID); $validEmailFields = EditableEmailField::get()->filter('ParentID', (int)$formID);
// for the subject, only one-line entry boxes make sense // for the subject, only one-line entry boxes make sense
$validSubjectFields = EditableTextField::get()->filter('ParentID', (int)$this->FormID)->filterByCallback(function($item, $list) { return (int)$item->getSetting('Rows') === 1; }); $validSubjectFields = EditableTextField::get()->filter('ParentID', (int)$formID)->filterByCallback(function($item, $list) { return (int)$item->getSetting('Rows') === 1; });
// predefined choices are also candidates // predefined choices are also candidates
$multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', (int)$this->FormID); $multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', (int)$formID);
$fields->insertAfter($dropdowns[] = new DropdownField( $fields->insertAfter($dropdowns[] = new DropdownField(
'SendEmailFromFieldID', 'SendEmailFromFieldID',
_t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'), _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'),
$validEmailFields->map('ID', 'Title') $validEmailFields->map('ID', 'Title')
), 'EmailReplyTo'); ), 'EmailReplyTo');
$validEmailFields = new ArrayList($validEmailFields->toArray()); $validEmailFields = new ArrayList($validEmailFields->toArray());
$validEmailFields->merge($multiOptionFields); $validEmailFields->merge($multiOptionFields);
$validSubjectFields->merge($multiOptionFields); $validSubjectFields->merge($multiOptionFields);
$fields->insertAfter($dropdowns[] = new DropdownField( $fields->insertAfter($dropdowns[] = new DropdownField(
'SendEmailToFieldID', 'SendEmailToFieldID',
_t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'), _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'),
$validEmailFields->map('ID', 'Title') $validEmailFields->map('ID', 'Title')
), 'EmailAddress'); ), 'EmailAddress');
$fields->insertAfter($dropdowns[] = new DropdownField( $fields->insertAfter($dropdowns[] = new DropdownField(
'SendEmailSubjectFieldID', 'SendEmailSubjectFieldID',
_t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'), _t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'),
$validSubjectFields->map('ID', 'Title') $validSubjectFields->map('ID', 'Title')
), 'EmailSubject'); ), 'EmailSubject');
foreach($dropdowns as $dropdown) { foreach($dropdowns as $dropdown) {
$dropdown->setHasEmptyDefault(true); $dropdown->setHasEmptyDefault(true);
$dropdown->setEmptyString(" "); $dropdown->setEmptyString(" ");
}
} }
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);