BUGFIX set email recipient on initial write()

This checks if the Form() relation ID is set, if not, then grab the current page from the session and use it's ID to get teh Editable Fields for dropdowns.

fixes #196
This commit is contained in:
muskie9 2014-12-01 14:46:02 -06:00
parent 7a76626cd2
commit 7e92af61fd

View File

@ -1167,14 +1167,14 @@ 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',
@ -1201,7 +1201,6 @@ class UserDefinedForm_EmailRecipient extends DataObject {
$dropdown->setHasEmptyDefault(true); $dropdown->setHasEmptyDefault(true);
$dropdown->setEmptyString(" "); $dropdown->setEmptyString(" ");
} }
}
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);