mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Move files into PSR-4 compatible locations
This commit is contained in:
parent
016a0bf2e4
commit
2e809de2ea
365
code/Model/UserDefinedForm.php
Executable file
365
code/Model/UserDefinedForm.php
Executable file
@ -0,0 +1,365 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserDefinedForm extends Page
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $icon = 'userforms/images/sitetree_icon.png';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $description = 'Adds a customizable form.';
|
||||
|
||||
/**
|
||||
* @var string Required Identifier
|
||||
*/
|
||||
private static $required_identifier = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $email_template_directory = 'userforms/templates/email/';
|
||||
|
||||
/**
|
||||
* Should this module automatically upgrade on dev/build?
|
||||
*
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $upgrade_on_build = true;
|
||||
|
||||
/**
|
||||
* Set this to true to disable automatic inclusion of CSS files
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $block_default_userforms_css = false;
|
||||
|
||||
/**
|
||||
* Set this to true to disable automatic inclusion of JavaScript files
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $block_default_userforms_js = false;
|
||||
|
||||
/**
|
||||
* Built in extensions required by this page
|
||||
* @config
|
||||
* @var array
|
||||
*/
|
||||
private static $extensions = array(
|
||||
'UserFormFieldEditorExtension'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Fields on the user defined form page.
|
||||
*/
|
||||
private static $db = array(
|
||||
"SubmitButtonText" => "Varchar",
|
||||
"ClearButtonText" => "Varchar",
|
||||
"OnCompleteMessage" => "HTMLText",
|
||||
"ShowClearButton" => "Boolean",
|
||||
'DisableSaveSubmissions' => 'Boolean',
|
||||
'EnableLiveValidation' => 'Boolean',
|
||||
'DisplayErrorMessagesAtTop' => 'Boolean',
|
||||
'DisableAuthenicatedFinishAction' => 'Boolean',
|
||||
'DisableCsrfSecurityToken' => 'Boolean'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Default values of variables when this page is created
|
||||
*/
|
||||
private static $defaults = array(
|
||||
'Content' => '$UserDefinedForm',
|
||||
'DisableSaveSubmissions' => 0,
|
||||
'OnCompleteMessage' => '<p>Thanks, we\'ve received your submission.</p>'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_many = array(
|
||||
"Submissions" => "SubmittedForm",
|
||||
"EmailRecipients" => "UserDefinedForm_EmailRecipient"
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @config
|
||||
*/
|
||||
private static $casting = array(
|
||||
'ErrorContainerID' => 'Text'
|
||||
);
|
||||
|
||||
/**
|
||||
* Error container selector which matches the element for grouped messages
|
||||
*
|
||||
* @var string
|
||||
* @config
|
||||
*/
|
||||
private static $error_container_id = 'error-container';
|
||||
|
||||
/**
|
||||
* The configuration used to determine whether a confirmation message is to
|
||||
* appear when navigating away from a partially completed form.
|
||||
*
|
||||
* @var boolean
|
||||
* @config
|
||||
*/
|
||||
private static $enable_are_you_sure = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @config
|
||||
*/
|
||||
private static $recipients_warning_enabled = false;
|
||||
|
||||
/**
|
||||
* Temporary storage of field ids when the form is duplicated.
|
||||
* Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldsFromTo = array();
|
||||
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
|
||||
|
||||
$self = $this;
|
||||
|
||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||
// define tabs
|
||||
$fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
|
||||
$fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients'));
|
||||
$fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
||||
|
||||
// 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', $self->OnCompleteMessage))
|
||||
);
|
||||
|
||||
$onCompleteFieldSet->addExtraClass('field');
|
||||
|
||||
$editor->setRows(3);
|
||||
$label->addExtraClass('left');
|
||||
|
||||
// Define config for email recipients
|
||||
$emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
|
||||
$emailRecipientsConfig->getComponentByType('GridFieldAddNewButton')
|
||||
->setButtonName(
|
||||
_t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
|
||||
);
|
||||
|
||||
// who do we email on submission
|
||||
$emailRecipients = new GridField(
|
||||
'EmailRecipients',
|
||||
_t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'),
|
||||
$self->EmailRecipients(),
|
||||
$emailRecipientsConfig
|
||||
);
|
||||
$emailRecipients
|
||||
->getConfig()
|
||||
->getComponentByType('GridFieldDetailForm')
|
||||
->setItemRequestClass('UserFormRecipientItemRequest');
|
||||
|
||||
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
|
||||
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
|
||||
$fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
|
||||
|
||||
|
||||
// view the submissions
|
||||
// make sure a numeric not a empty string is checked against this int column for SQL server
|
||||
$parentID = (!empty($self->ID)) ? (int) $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
|
||||
SELECT "SubmittedFormField"."Name" as "Name", COALESCE("EditableFormField"."Title", "SubmittedFormField"."Title") as "Title", COALESCE("EditableFormField"."Sort", 999) AS "Sort"
|
||||
FROM "SubmittedFormField"
|
||||
LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID"
|
||||
LEFT JOIN "EditableFormField" ON "EditableFormField"."Name" = "SubmittedFormField"."Name" AND "EditableFormField"."ParentID" = '$parentID'
|
||||
WHERE "SubmittedForm"."ParentID" = '$parentID'
|
||||
ORDER BY "Sort", "Title"
|
||||
SQL;
|
||||
// Sanitise periods in title
|
||||
$columns = array();
|
||||
foreach (DB::query($columnSQL)->map() as $name => $title) {
|
||||
$columns[$name] = trim(strtr($title, '.', ' '));
|
||||
}
|
||||
|
||||
$config = new GridFieldConfig();
|
||||
$config->addComponent(new GridFieldToolbarHeader());
|
||||
$config->addComponent($sort = new GridFieldSortableHeader());
|
||||
$config->addComponent($filter = new UserFormsGridFieldFilterHeader());
|
||||
$config->addComponent(new GridFieldDataColumns());
|
||||
$config->addComponent(new GridFieldEditButton());
|
||||
$config->addComponent(new GridFieldDeleteAction());
|
||||
$config->addComponent(new GridFieldPageCount('toolbar-header-right'));
|
||||
$config->addComponent($pagination = new GridFieldPaginator(25));
|
||||
$config->addComponent(new GridFieldDetailForm());
|
||||
$config->addComponent(new GridFieldButtonRow('after'));
|
||||
$config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
|
||||
$config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
|
||||
|
||||
// show user form items in the summary tab
|
||||
$summaryarray = array(
|
||||
'ID' => 'ID',
|
||||
'Created' => 'Created',
|
||||
'LastEdited' => 'Last Edited'
|
||||
);
|
||||
foreach(EditableFormField::get()->filter(array("ParentID" => $parentID)) as $eff) {
|
||||
if($eff->ShowInSummary) {
|
||||
$summaryarray[$eff->Name] = $eff->Title ?: $eff->Name;
|
||||
}
|
||||
}
|
||||
|
||||
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields($summaryarray);
|
||||
|
||||
/**
|
||||
* Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
|
||||
*/
|
||||
if (class_exists('GridFieldBulkManager')) {
|
||||
$config->addComponent(new GridFieldBulkManager());
|
||||
}
|
||||
|
||||
$sort->setThrowExceptionOnBadDataType(false);
|
||||
$filter->setThrowExceptionOnBadDataType(false);
|
||||
$pagination->setThrowExceptionOnBadDataType(false);
|
||||
|
||||
// attach every column to the print view form
|
||||
$columns['Created'] = 'Created';
|
||||
$columns['SubmittedBy.Email'] = 'Submitter';
|
||||
$filter->setColumns($columns);
|
||||
|
||||
// print configuration
|
||||
|
||||
$print->setPrintHasHeader(true);
|
||||
$print->setPrintColumns($columns);
|
||||
|
||||
// export configuration
|
||||
$export->setCsvHasHeader(true);
|
||||
$export->setExportColumns($columns);
|
||||
|
||||
$submissions = GridField::create(
|
||||
'Submissions',
|
||||
_t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
|
||||
$self->Submissions()->sort('Created', 'DESC'),
|
||||
$config
|
||||
);
|
||||
$fields->addFieldToTab('Root.Submissions', $submissions);
|
||||
$fields->addFieldToTab(
|
||||
'Root.FormOptions',
|
||||
CheckboxField::create(
|
||||
'DisableSaveSubmissions',
|
||||
_t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
|
||||
$fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
|
||||
"<p class=\"message warning\">" . _t("UserDefinedForm.NORECIPIENTS",
|
||||
"Warning: You have not configured any recipients. Form submissions may be missed.")
|
||||
. "</p>"), "Title");
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow overriding the EmailRecipients on a {@link DataExtension}
|
||||
* so you can customise who receives an email.
|
||||
* Converts the RelationList to an ArrayList so that manipulation
|
||||
* of the original source data isn't possible.
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function FilteredEmailRecipients($data = null, $form = null)
|
||||
{
|
||||
$recipients = new ArrayList($this->EmailRecipients()->toArray());
|
||||
|
||||
// Filter by rules
|
||||
$recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
|
||||
/** @var UserDefinedForm_EmailRecipient $recipient */
|
||||
return $recipient->canSend($data, $form);
|
||||
});
|
||||
|
||||
$this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
|
||||
|
||||
return $recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom options for the form. You can extend the built in options by
|
||||
* using {@link updateFormOptions()}
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFormOptions()
|
||||
{
|
||||
$submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
|
||||
$clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
|
||||
|
||||
$options = new FieldList(
|
||||
new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
|
||||
new TextField("ClearButtonText", _t('UserDefinedForm.TEXTONCLEAR', 'Text on clear button:'), $clear),
|
||||
new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
|
||||
new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
|
||||
new CheckboxField("DisplayErrorMessagesAtTop", _t('UserDefinedForm.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
|
||||
new CheckboxField('DisableCsrfSecurityToken', _t('UserDefinedForm.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
|
||||
new CheckboxField('DisableAuthenicatedFinishAction', _t('UserDefinedForm.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
|
||||
);
|
||||
|
||||
$this->extend('updateFormOptions', $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML id of the error container displayed above the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorContainerID()
|
||||
{
|
||||
return $this->config()->error_container_id;
|
||||
}
|
||||
|
||||
public function requireDefaultRecords()
|
||||
{
|
||||
parent::requireDefaultRecords();
|
||||
|
||||
if (!$this->config()->upgrade_on_build) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform migrations
|
||||
Injector::inst()
|
||||
->create('UserFormsUpgradeService')
|
||||
->setQuiet(true)
|
||||
->run();
|
||||
|
||||
DB::alteration_message('Migrated userforms', 'changed');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate formfields
|
||||
*/
|
||||
public function getCMSValidator()
|
||||
{
|
||||
return new UserFormValidator();
|
||||
}
|
||||
}
|
366
code/model/UserDefinedForm.php → code/Model/UserDefinedFormController.php
Executable file → Normal file
366
code/model/UserDefinedForm.php → code/Model/UserDefinedFormController.php
Executable file → Normal file
@ -1,376 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserDefinedForm extends Page
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $icon = 'userforms/images/sitetree_icon.png';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $description = 'Adds a customizable form.';
|
||||
|
||||
/**
|
||||
* @var string Required Identifier
|
||||
*/
|
||||
private static $required_identifier = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $email_template_directory = 'userforms/templates/email/';
|
||||
|
||||
/**
|
||||
* Should this module automatically upgrade on dev/build?
|
||||
*
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $upgrade_on_build = true;
|
||||
|
||||
/**
|
||||
* Set this to true to disable automatic inclusion of CSS files
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $block_default_userforms_css = false;
|
||||
|
||||
/**
|
||||
* Set this to true to disable automatic inclusion of JavaScript files
|
||||
* @config
|
||||
* @var bool
|
||||
*/
|
||||
private static $block_default_userforms_js = false;
|
||||
|
||||
/**
|
||||
* Built in extensions required by this page
|
||||
* @config
|
||||
* @var array
|
||||
*/
|
||||
private static $extensions = array(
|
||||
'UserFormFieldEditorExtension'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Fields on the user defined form page.
|
||||
*/
|
||||
private static $db = array(
|
||||
"SubmitButtonText" => "Varchar",
|
||||
"ClearButtonText" => "Varchar",
|
||||
"OnCompleteMessage" => "HTMLText",
|
||||
"ShowClearButton" => "Boolean",
|
||||
'DisableSaveSubmissions' => 'Boolean',
|
||||
'EnableLiveValidation' => 'Boolean',
|
||||
'DisplayErrorMessagesAtTop' => 'Boolean',
|
||||
'DisableAuthenicatedFinishAction' => 'Boolean',
|
||||
'DisableCsrfSecurityToken' => 'Boolean'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Default values of variables when this page is created
|
||||
*/
|
||||
private static $defaults = array(
|
||||
'Content' => '$UserDefinedForm',
|
||||
'DisableSaveSubmissions' => 0,
|
||||
'OnCompleteMessage' => '<p>Thanks, we\'ve received your submission.</p>'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_many = array(
|
||||
"Submissions" => "SubmittedForm",
|
||||
"EmailRecipients" => "UserDefinedForm_EmailRecipient"
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @config
|
||||
*/
|
||||
private static $casting = array(
|
||||
'ErrorContainerID' => 'Text'
|
||||
);
|
||||
|
||||
/**
|
||||
* Error container selector which matches the element for grouped messages
|
||||
*
|
||||
* @var string
|
||||
* @config
|
||||
*/
|
||||
private static $error_container_id = 'error-container';
|
||||
|
||||
/**
|
||||
* The configuration used to determine whether a confirmation message is to
|
||||
* appear when navigating away from a partially completed form.
|
||||
*
|
||||
* @var boolean
|
||||
* @config
|
||||
*/
|
||||
private static $enable_are_you_sure = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @config
|
||||
*/
|
||||
private static $recipients_warning_enabled = false;
|
||||
|
||||
/**
|
||||
* Temporary storage of field ids when the form is duplicated.
|
||||
* Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldsFromTo = array();
|
||||
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
|
||||
|
||||
$self = $this;
|
||||
|
||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||
// define tabs
|
||||
$fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
|
||||
$fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients'));
|
||||
$fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
||||
|
||||
// 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', $self->OnCompleteMessage))
|
||||
);
|
||||
|
||||
$onCompleteFieldSet->addExtraClass('field');
|
||||
|
||||
$editor->setRows(3);
|
||||
$label->addExtraClass('left');
|
||||
|
||||
// Define config for email recipients
|
||||
$emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
|
||||
$emailRecipientsConfig->getComponentByType('GridFieldAddNewButton')
|
||||
->setButtonName(
|
||||
_t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
|
||||
);
|
||||
|
||||
// who do we email on submission
|
||||
$emailRecipients = new GridField(
|
||||
'EmailRecipients',
|
||||
_t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'),
|
||||
$self->EmailRecipients(),
|
||||
$emailRecipientsConfig
|
||||
);
|
||||
$emailRecipients
|
||||
->getConfig()
|
||||
->getComponentByType('GridFieldDetailForm')
|
||||
->setItemRequestClass('UserFormRecipientItemRequest');
|
||||
|
||||
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
|
||||
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
|
||||
$fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
|
||||
|
||||
|
||||
// view the submissions
|
||||
// make sure a numeric not a empty string is checked against this int column for SQL server
|
||||
$parentID = (!empty($self->ID)) ? (int) $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
|
||||
SELECT "SubmittedFormField"."Name" as "Name", COALESCE("EditableFormField"."Title", "SubmittedFormField"."Title") as "Title", COALESCE("EditableFormField"."Sort", 999) AS "Sort"
|
||||
FROM "SubmittedFormField"
|
||||
LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID"
|
||||
LEFT JOIN "EditableFormField" ON "EditableFormField"."Name" = "SubmittedFormField"."Name" AND "EditableFormField"."ParentID" = '$parentID'
|
||||
WHERE "SubmittedForm"."ParentID" = '$parentID'
|
||||
ORDER BY "Sort", "Title"
|
||||
SQL;
|
||||
// Sanitise periods in title
|
||||
$columns = array();
|
||||
foreach (DB::query($columnSQL)->map() as $name => $title) {
|
||||
$columns[$name] = trim(strtr($title, '.', ' '));
|
||||
}
|
||||
|
||||
$config = new GridFieldConfig();
|
||||
$config->addComponent(new GridFieldToolbarHeader());
|
||||
$config->addComponent($sort = new GridFieldSortableHeader());
|
||||
$config->addComponent($filter = new UserFormsGridFieldFilterHeader());
|
||||
$config->addComponent(new GridFieldDataColumns());
|
||||
$config->addComponent(new GridFieldEditButton());
|
||||
$config->addComponent(new GridFieldDeleteAction());
|
||||
$config->addComponent(new GridFieldPageCount('toolbar-header-right'));
|
||||
$config->addComponent($pagination = new GridFieldPaginator(25));
|
||||
$config->addComponent(new GridFieldDetailForm());
|
||||
$config->addComponent(new GridFieldButtonRow('after'));
|
||||
$config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
|
||||
$config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
|
||||
|
||||
// show user form items in the summary tab
|
||||
$summaryarray = array(
|
||||
'ID' => 'ID',
|
||||
'Created' => 'Created',
|
||||
'LastEdited' => 'Last Edited'
|
||||
);
|
||||
foreach(EditableFormField::get()->filter(array("ParentID" => $parentID)) as $eff) {
|
||||
if($eff->ShowInSummary) {
|
||||
$summaryarray[$eff->Name] = $eff->Title ?: $eff->Name;
|
||||
}
|
||||
}
|
||||
|
||||
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields($summaryarray);
|
||||
|
||||
/**
|
||||
* Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
|
||||
*/
|
||||
if (class_exists('GridFieldBulkManager')) {
|
||||
$config->addComponent(new GridFieldBulkManager());
|
||||
}
|
||||
|
||||
$sort->setThrowExceptionOnBadDataType(false);
|
||||
$filter->setThrowExceptionOnBadDataType(false);
|
||||
$pagination->setThrowExceptionOnBadDataType(false);
|
||||
|
||||
// attach every column to the print view form
|
||||
$columns['Created'] = 'Created';
|
||||
$columns['SubmittedBy.Email'] = 'Submitter';
|
||||
$filter->setColumns($columns);
|
||||
|
||||
// print configuration
|
||||
|
||||
$print->setPrintHasHeader(true);
|
||||
$print->setPrintColumns($columns);
|
||||
|
||||
// export configuration
|
||||
$export->setCsvHasHeader(true);
|
||||
$export->setExportColumns($columns);
|
||||
|
||||
$submissions = GridField::create(
|
||||
'Submissions',
|
||||
_t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
|
||||
$self->Submissions()->sort('Created', 'DESC'),
|
||||
$config
|
||||
);
|
||||
$fields->addFieldToTab('Root.Submissions', $submissions);
|
||||
$fields->addFieldToTab(
|
||||
'Root.FormOptions',
|
||||
CheckboxField::create(
|
||||
'DisableSaveSubmissions',
|
||||
_t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
|
||||
$fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
|
||||
"<p class=\"message warning\">" . _t("UserDefinedForm.NORECIPIENTS",
|
||||
"Warning: You have not configured any recipients. Form submissions may be missed.")
|
||||
. "</p>"), "Title");
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow overriding the EmailRecipients on a {@link DataExtension}
|
||||
* so you can customise who receives an email.
|
||||
* Converts the RelationList to an ArrayList so that manipulation
|
||||
* of the original source data isn't possible.
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function FilteredEmailRecipients($data = null, $form = null)
|
||||
{
|
||||
$recipients = new ArrayList($this->EmailRecipients()->toArray());
|
||||
|
||||
// Filter by rules
|
||||
$recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
|
||||
/** @var UserDefinedForm_EmailRecipient $recipient */
|
||||
return $recipient->canSend($data, $form);
|
||||
});
|
||||
|
||||
$this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
|
||||
|
||||
return $recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom options for the form. You can extend the built in options by
|
||||
* using {@link updateFormOptions()}
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFormOptions()
|
||||
{
|
||||
$submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
|
||||
$clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
|
||||
|
||||
$options = new FieldList(
|
||||
new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
|
||||
new TextField("ClearButtonText", _t('UserDefinedForm.TEXTONCLEAR', 'Text on clear button:'), $clear),
|
||||
new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
|
||||
new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
|
||||
new CheckboxField("DisplayErrorMessagesAtTop", _t('UserDefinedForm.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
|
||||
new CheckboxField('DisableCsrfSecurityToken', _t('UserDefinedForm.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
|
||||
new CheckboxField('DisableAuthenicatedFinishAction', _t('UserDefinedForm.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
|
||||
);
|
||||
|
||||
$this->extend('updateFormOptions', $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML id of the error container displayed above the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorContainerID()
|
||||
{
|
||||
return $this->config()->error_container_id;
|
||||
}
|
||||
|
||||
public function requireDefaultRecords()
|
||||
{
|
||||
parent::requireDefaultRecords();
|
||||
|
||||
if (!$this->config()->upgrade_on_build) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform migrations
|
||||
Injector::inst()
|
||||
->create('UserFormsUpgradeService')
|
||||
->setQuiet(true)
|
||||
->run();
|
||||
|
||||
DB::alteration_message('Migrated userforms', 'changed');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate formfields
|
||||
*/
|
||||
public function getCMSValidator()
|
||||
{
|
||||
return new UserFormValidator();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Controller for the {@link UserDefinedForm} page type.
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserDefinedForm_Controller extends Page_Controller
|
||||
class UserDefinedFormController extends PageController
|
||||
{
|
||||
|
||||
private static $finished_anchor = '#uff';
|
@ -30,10 +30,14 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "~3.2",
|
||||
"silverstripe/cms": "~3.2",
|
||||
"symbiote/silverstripe-gridfieldextensions": "~1.4",
|
||||
"silverstripe/segment-field": "^1.0"
|
||||
"silverstripe/framework": "^4@dev",
|
||||
"silverstripe/cms": "^4@dev",
|
||||
"symbiote/silverstripe-gridfieldextensions": "^3@dev",
|
||||
"silverstripe/segment-field": "^2@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"colymba/gridfield-bulk-editing-tools": "Allows for bulk management of form submissions",
|
||||
@ -44,5 +48,7 @@
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0.x-dev"
|
||||
}
|
||||
}
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
@ -50,8 +50,8 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
|
||||
}
|
||||
|
||||
|
||||
public function testGetCMSFieldsShowInSummary()
|
||||
|
||||
public function testGetCMSFieldsShowInSummary()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'summary-rules-form');
|
||||
@ -69,7 +69,7 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
$this->assertNotContains('SummaryHide', array_keys($summaryFields), 'Summary field showing displayed field');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testEmailRecipientPopup()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
@ -20,7 +20,7 @@ EditableOption:
|
||||
option-1:
|
||||
Name: Option1
|
||||
Title: Option 1
|
||||
|
||||
|
||||
option-2:
|
||||
Name: Option2
|
||||
Title: Option 2
|
||||
@ -60,44 +60,44 @@ EditableOption:
|
||||
option-9:
|
||||
Name: Option9
|
||||
Title: Green
|
||||
|
||||
|
||||
EditableTextField:
|
||||
basic-text:
|
||||
Name: basic-text-name
|
||||
Title: Basic Text Field
|
||||
|
||||
|
||||
basic-text-2:
|
||||
Name: basic-text-name
|
||||
Title: Basic Text Field
|
||||
|
||||
|
||||
your-name-field:
|
||||
Name: your-name
|
||||
Title: Name
|
||||
|
||||
|
||||
address-field:
|
||||
Name: address
|
||||
Title: Address
|
||||
|
||||
|
||||
street-field:
|
||||
Name: street
|
||||
Title: Street
|
||||
|
||||
|
||||
city-field:
|
||||
Name: city
|
||||
Title: City
|
||||
|
||||
|
||||
required-text:
|
||||
Name: required-text-field
|
||||
Title: Required Text Field
|
||||
CustomErrorMessage: Custom Error Message
|
||||
Required: true
|
||||
|
||||
|
||||
field-1:
|
||||
Name: Field1
|
||||
|
||||
field-2:
|
||||
Name: Field2
|
||||
|
||||
|
||||
some-field:
|
||||
Name: SomeField
|
||||
|
||||
@ -106,12 +106,12 @@ EditableTextField:
|
||||
Title: Required Text Field
|
||||
Required: true
|
||||
CustomErrorMessage: 'This field is required'
|
||||
|
||||
|
||||
summary-show:
|
||||
Name: SummaryShow
|
||||
Title: Summary Text Field
|
||||
ShowInSummary: true
|
||||
|
||||
|
||||
summary-hide:
|
||||
Name: SummaryHide
|
||||
Title: Summary Text Field
|
||||
@ -122,21 +122,21 @@ EditableDropdown:
|
||||
Name: basic-dropdown
|
||||
Title: Basic Dropdown Field
|
||||
Options: =>EditableOption.option-1, =>EditableOption.option-2
|
||||
|
||||
|
||||
department-dropdown:
|
||||
Name: department
|
||||
Title: Department
|
||||
Options: =>EditableOption.department-1, =>EditableOption.department-2
|
||||
|
||||
|
||||
EditableCheckbox:
|
||||
checkbox-1:
|
||||
Name: checkbox-1
|
||||
Title: Checkbox 1
|
||||
|
||||
|
||||
checkbox-2:
|
||||
Name: checkbox-1
|
||||
Title: Checkbox 1
|
||||
|
||||
|
||||
EditableCheckboxGroupField:
|
||||
checkbox-group:
|
||||
Name: check-box-group
|
||||
@ -163,11 +163,11 @@ EditableRadioField:
|
||||
Name: radio-option
|
||||
Title: Radio Option
|
||||
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
||||
|
||||
|
||||
EditableFieldGroupEnd:
|
||||
group1end:
|
||||
Name: group1end
|
||||
|
||||
|
||||
EditableFieldGroup:
|
||||
group1start:
|
||||
Name: group1start
|
||||
@ -205,31 +205,31 @@ UserDefinedForm_EmailRecipient:
|
||||
EmailAddress: test@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
|
||||
|
||||
no-html:
|
||||
EmailAddress: nohtml@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
SendPlain: true
|
||||
|
||||
|
||||
no-data:
|
||||
EmailAddress: nodata@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
EmailFrom: no-reply@example.com
|
||||
HideFormData: true
|
||||
|
||||
|
||||
unfiltered-recipient-1:
|
||||
EmailAddress: unfiltered@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
|
||||
|
||||
filtered-recipient-1:
|
||||
EmailAddress: filtered1@example.com
|
||||
EmailSubject: Email Subject
|
||||
EmailFrom: no-reply@example.com
|
||||
CustomRules: =>UserDefinedForm_EmailRecipientCondition.blank-rule, =>UserDefinedForm_EmailRecipientCondition.not-blank-rule, =>UserDefinedForm_EmailRecipientCondition.equals-rule, =>UserDefinedForm_EmailRecipientCondition.not-equals-rule
|
||||
CustomRulesCondition: 'And'
|
||||
|
||||
|
||||
filtered-recipient-2:
|
||||
EmailAddress: filtered2@example.com
|
||||
EmailSubject: Email Subject
|
||||
@ -253,29 +253,29 @@ UserDefinedForm:
|
||||
Title: User Defined Form
|
||||
Fields: =>EditableFormStep.form1step1,=>EditableTextField.basic-text
|
||||
EmailRecipients: =>UserDefinedForm_EmailRecipient.recipient-1, =>UserDefinedForm_EmailRecipient.no-html, =>UserDefinedForm_EmailRecipient.no-data
|
||||
|
||||
|
||||
page-with-group:
|
||||
Content: 'Page with group'
|
||||
Title: 'page with group'
|
||||
Fields: =>EditableFormStep.form7step1, =>EditableFieldGroup.group1start, =>EditableTextField.some-field, =>EditableFieldGroupEnd.group1end
|
||||
|
||||
|
||||
form-with-reset-and-custom-action:
|
||||
Title: Form with Reset Action
|
||||
SubmitButtonText: Custom Button
|
||||
ShowClearButton: true
|
||||
|
||||
|
||||
validation-form:
|
||||
Title: Validation Form
|
||||
Fields: =>EditableFormStep.form3step1,=>EditableTextField.required-text
|
||||
|
||||
|
||||
custom-rules-form:
|
||||
Title: Custom Rules Form
|
||||
Fields: =>EditableCheckbox.checkbox-2, =>EditableTextField.basic-text-2
|
||||
|
||||
|
||||
summary-rules-form:
|
||||
Title: Summary Fields Form
|
||||
Fields: =>EditableTextField.summary-show, =>EditableTextField.summary-hide
|
||||
|
||||
|
||||
empty-form:
|
||||
Title: Empty Form
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
class UserFormsVersionedTest extends SapphireTest
|
||||
class UserFormsVersionedTaskTest extends SapphireTest
|
||||
{
|
||||
protected static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
Loading…
Reference in New Issue
Block a user