mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #260 from 3Dgoo/feature/before-update-cms-fields
Wrapping getCMSFields fields with beforeUpdateCMSFields
This commit is contained in:
commit
7badef5c35
@ -60,22 +60,23 @@ class UserDefinedForm extends Page {
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
// call updateCMSFields after userforms
|
||||
SiteTree::disableCMSFieldsExtensions();
|
||||
$fields = parent::getCMSFields();
|
||||
SiteTree::enableCMSFieldsExtensions();
|
||||
|
||||
$self = $this;
|
||||
|
||||
$this->beforeUpdateCMSFields(function($fields) use ($self) {
|
||||
|
||||
// define tabs
|
||||
$fields->findOrMakeTab('Root.FormContent', _t('UserDefinedForm.FORM', 'Form'));
|
||||
$fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
|
||||
$fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
||||
|
||||
// field editor
|
||||
$fields->addFieldToTab("Root.FormContent", new FieldEditor("Fields", 'Fields', "", $this ));
|
||||
$fields->addFieldToTab('Root.FormContent', new FieldEditor('Fields', 'Fields', '', $self ));
|
||||
|
||||
// text to show on complete
|
||||
$onCompleteFieldSet = new CompositeField(
|
||||
$label = new LabelField('OnCompleteMessageLabel',_t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
|
||||
$editor = new HtmlEditorField( "OnCompleteMessage", "", _t('UserDefinedForm.ONCOMPLETEMESSAGE', $this->OnCompleteMessage))
|
||||
$editor = new HtmlEditorField( 'OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
|
||||
);
|
||||
|
||||
$onCompleteFieldSet->addExtraClass('field');
|
||||
@ -95,25 +96,25 @@ class UserDefinedForm extends Page {
|
||||
);
|
||||
|
||||
// who do we email on submission
|
||||
$emailRecipients = new GridField("EmailRecipients", _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $this->EmailRecipients(), GridFieldConfig_RecordEditor::create(10));
|
||||
$emailRecipients = new GridField('EmailRecipients', _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'), $self->EmailRecipients(), GridFieldConfig_RecordEditor::create(10));
|
||||
$emailRecipients->getConfig()->getComponentByType('GridFieldAddNewButton')->setButtonName(
|
||||
_t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
|
||||
);
|
||||
|
||||
$fields->addFieldsToTab("Root.FormOptions", $onCompleteFieldSet);
|
||||
$fields->addFieldToTab("Root.FormOptions", $emailRecipients);
|
||||
$fields->addFieldsToTab("Root.FormOptions", $this->getFormOptions());
|
||||
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
|
||||
$fields->addFieldToTab('Root.FormOptions', $emailRecipients);
|
||||
$fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
|
||||
|
||||
|
||||
// view the submissions
|
||||
$submissions = new GridField(
|
||||
"Submissions",
|
||||
'Submissions',
|
||||
_t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
|
||||
$this->Submissions()->sort('Created', 'DESC')
|
||||
$self->Submissions()->sort('Created', 'DESC')
|
||||
);
|
||||
|
||||
// make sure a numeric not a empty string is checked against this int column for SQL server
|
||||
$parentID = (!empty($this->ID)) ? $this->ID : 0;
|
||||
$parentID = (!empty($self->ID)) ? $self->ID : 0;
|
||||
|
||||
// get a list of all field names and values used for print and export CSV views of the GridField below.
|
||||
$columnSQL = <<<SQL
|
||||
@ -155,6 +156,7 @@ SQL;
|
||||
$filter->setColumns($columns);
|
||||
|
||||
// print configuration
|
||||
|
||||
$print->setPrintHasHeader(true);
|
||||
$print->setPrintColumns($columns);
|
||||
|
||||
@ -163,10 +165,12 @@ SQL;
|
||||
$export->setExportColumns($columns);
|
||||
|
||||
$submissions->setConfig($config);
|
||||
$fields->addFieldToTab("Root.Submissions", $submissions);
|
||||
$fields->addFieldToTab("Root.FormOptions", new CheckboxField('DisableSaveSubmissions',_t('UserDefinedForm.SAVESUBMISSIONS',"Disable Saving Submissions to Server")));
|
||||
$fields->addFieldToTab('Root.Submissions', $submissions);
|
||||
$fields->addFieldToTab('Root.FormOptions', new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')));
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
});
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
@ -50,14 +50,17 @@ class SubmittedForm extends DataObject {
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$self = $this;
|
||||
|
||||
$this->beforeUpdateCMSFields(function($fields) use ($self) {
|
||||
$fields->removeByName('Values');
|
||||
$fields->dataFieldByName('SubmittedByID')->setDisabled(true);
|
||||
|
||||
$values = new GridField(
|
||||
"Values",
|
||||
"SubmittedFormField",
|
||||
$this->Values()->sort('Created', 'ASC')
|
||||
'Values',
|
||||
'SubmittedFormField',
|
||||
$self->Values()->sort('Created', 'ASC')
|
||||
);
|
||||
|
||||
$config = new GridFieldConfig();
|
||||
@ -67,6 +70,9 @@ class SubmittedForm extends DataObject {
|
||||
$values->setConfig($config);
|
||||
|
||||
$fields->addFieldToTab('Root.Main', $values);
|
||||
});
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user