Merge pull request #1 from silverstripe/master

Syncing fork repo with base repository
This commit is contained in:
Liongold 2014-07-12 17:50:03 +02:00
commit e6eefe9528
4 changed files with 96 additions and 52 deletions

View File

@ -223,6 +223,16 @@ class FieldEditor extends FormField {
$className = (isset($_REQUEST['Type'])) ? $_REQUEST['Type'] : '';
if(!$className) {
// A possible reason for the classname being blank is because we have execeded
// the number of input requests
// http://www.php.net/manual/en/info.configuration.php#ini.max-input-vars
$maxRequests = ini_get('max_input_vars');
$numRequests = count($_REQUEST, COUNT_RECURSIVE);
if ($numRequests > $maxRequests) {
$error = sprintf('You have exceded the maximum number %s of input requests',
"[$maxRequests]");
user_error($error, E_USER_WARNING);
}
user_error('Please select a field type to created', E_USER_WARNING);
}

View File

@ -942,6 +942,8 @@ JS
}
}
$submittedField->extend('onPopulationFromField', $field);
if(!$this->DisableSaveSubmissions) {
$submittedField->write();
}
@ -977,8 +979,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 +1003,15 @@ JS
}
}
// check to see if there is a dynamic subject
if($recipient->SendEmailSubjectField()) {
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
if($submittedFormField && trim($submittedFormField->Value)) {
$email->setSubject($submittedFormField->Value);
}
}
$this->extend('updateEmail', $email, $recipient, $emailData);
if($recipient->SendPlain) {
@ -1020,6 +1031,8 @@ JS
}
}
$submittedForm->extend('updateAfterProcess');
Session::clear("FormInfo.{$form->FormName()}.errors");
Session::clear("FormInfo.{$form->FormName()}.data");
@ -1039,8 +1052,12 @@ JS
Session::set('FormProcessedNum',$randNum);
}
}
if(!$this->DisableSaveSubmissions) {
Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
}
return $this->redirect($this->Link() . 'finished' . $referrer);
return $this->redirect($this->Link('finished') . $referrer);
}
/**
@ -1050,6 +1067,12 @@ JS
* @return ViewableData
*/
public function finished() {
$submission = Session::get('userformssubmission'. $this->ID);
if($submission) {
$submission = SubmittedForm::get()->byId($submission);
}
$referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
$formProcessed = Session::get('FormProcessed');
@ -1070,10 +1093,10 @@ JS
Session::clear('FormProcessed');
return $this->customise(array(
'Content' => $this->customise(
array(
'Link' => $referrer
))->renderWith('ReceivedFormSubmission'),
'Content' => $this->customise(array(
'Submission' => $submission,
'Link' => $referrer
))->renderWith('ReceivedFormSubmission'),
'Form' => '',
));
}
@ -1100,7 +1123,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,48 +1153,37 @@ 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 . "'");
// if they have email fields then we could send from it
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');
}
$validEmailFields = EditableEmailField::get()->filter('ParentID', (int)$this->FormID);
// 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; });
// predefined choices are also candidates
$multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', (int)$this->FormID);
// if they have multiple options
if($multiOptionFields || $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($multiOptionFields && $validEmailFields) {
$multiOptionFields = $multiOptionFields->toArray();
$multiOptionFields = array_merge(
$multiOptionFields,
$validEmailFields->toArray()
);
$validEmailFields = new ArrayList($validEmailFields->toArray());
$validEmailFields->merge($multiOptionFields);
$validSubjectFields->merge($multiOptionFields);
$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
), 'EmailAddress');
}
$fields->insertAfter($dropdowns[] = new DropdownField(
'SendEmailToFieldID',
_t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'),
$validEmailFields->map('ID', 'Title')
), 'EmailAddress');
$fields->insertAfter($dropdowns[] = new DropdownField(
'SendEmailSubjectFieldID',
_t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'),
$validSubjectFields->map('ID', 'Title')
), 'EmailSubject');
if($dropdowns) {
foreach($dropdowns as $dropdown) {
$dropdown->setHasEmptyDefault(true);
$dropdown->setEmptyString(" ");
}
foreach($dropdowns as $dropdown) {
$dropdown->setHasEmptyDefault(true);
$dropdown->setEmptyString(" ");
}
}
@ -1242,4 +1255,4 @@ class UserDefinedForm_SubmittedFormEmail extends Email {
public function setReplyTo($email) {
$this->customHeaders['Reply-To'] = $email;
}
}
}

View File

@ -191,8 +191,8 @@ class EditableFormField extends DataObject {
* @param array The permissible CSS classes to add
*/
public function setAllowedCss(array $allowed) {
if (is_array($allowed_css)){
foreach ($allowed_css as $k => $v){
if (is_array($allowed)) {
foreach ($allowed as $k => $v) {
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
}
}
@ -337,14 +337,16 @@ class EditableFormField extends DataObject {
}
/**
* How to save the data submitted in this field into
* the database object which this field represents.
* How to save the data submitted in this field into the database object
* which this field represents.
*
* Any class's which call this should also call
* {@link parent::populateFromPostData()} to ensure
* that this method is called
* {@link parent::populateFromPostData()} to ensure that this method is
* called
*
* @access public
*
* @param array $data
*/
public function populateFromPostData($data) {
$this->Title = (isset($data['Title'])) ? $data['Title']: "";
@ -385,7 +387,8 @@ class EditableFormField extends DataObject {
$this->CustomRules = serialize($rules);
}
$this->extend('onPopulateFromPostData', $data);
$this->write();
}

View File

@ -26,6 +26,24 @@ class EditableOption extends DataObject {
"Versioned('Stage', 'Live')"
);
/**
* @param Member $member
*
* @return boolean
*/
public function canEdit($member = null) {
return ($this->Parent()->canEdit($member));
}
/**
* @param Member $member
*
* @return boolean
*/
public function canDelete($member = null) {
return ($this->Parent()->canDelete($member));
}
/**
* Template for the editing view of this option field
*/