mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
remove trailing spaces in the codebase
This commit is contained in:
parent
99e771f942
commit
20cc915236
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Extension to the build in SilverStripe {@link GridField} to allow for
|
||||
* filtering {@link SubmittedForm} objects in the submissions tab by
|
||||
* Extension to the build in SilverStripe {@link GridField} to allow for
|
||||
* filtering {@link SubmittedForm} objects in the submissions tab by
|
||||
* entering the value of a field
|
||||
*
|
||||
* @package userforms
|
||||
@ -41,7 +41,7 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
|
||||
$selectedField = $state->filter;
|
||||
$selectedValue = $state->value;
|
||||
|
||||
|
||||
// show dropdown of all the fields available from the submitted form fields
|
||||
// that have been saved. Takes the titles from the currently live form.
|
||||
$columnField = new DropdownField('FieldNameFilter', '');
|
||||
@ -58,7 +58,7 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
$valueField->addExtraClass('ss-gridfield-sort');
|
||||
$valueField->addExtraClass('no-change-track');
|
||||
$valueField->setAttribute(
|
||||
'placeholder',
|
||||
'placeholder',
|
||||
_t('UserFormsGridFieldFilterHeader.WHEREVALUEIS', 'where value is..'
|
||||
));
|
||||
|
||||
@ -114,10 +114,10 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
if($filter = $state->UserFormsGridField->toArray()) {
|
||||
if(isset($filter['filter']) && $filter['filter'] && isset($filter['value']) && $filter['value']) {
|
||||
$dataList = $dataList->where(sprintf("
|
||||
SELECT COUNT(*) FROM SubmittedFormField
|
||||
WHERE (
|
||||
SELECT COUNT(*) FROM SubmittedFormField
|
||||
WHERE (
|
||||
ParentID = SubmittedForm.ID AND
|
||||
Name = '%s' AND
|
||||
Name = '%s' AND
|
||||
Value LIKE '%s'
|
||||
) > 0",
|
||||
|
||||
|
@ -33,7 +33,7 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*/
|
||||
public function getFieldEditorGrid() {
|
||||
Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
|
||||
|
||||
|
||||
$fields = $this->owner->Fields();
|
||||
|
||||
$this->createInitialFormStep(true);
|
||||
|
@ -120,7 +120,7 @@ class UserFormValidator extends RequiredFields {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class UserFormsGroupField extends UserFormsCompositeField {
|
||||
// Legend defaults to title
|
||||
return parent::getLegend() ?: $this->Title();
|
||||
}
|
||||
|
||||
|
||||
public function processNext(EditableFormField $field) {
|
||||
// When ending a group, jump up one level
|
||||
if($field instanceof EditableFieldGroupEnd) {
|
||||
|
@ -145,7 +145,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
}
|
||||
$this->modelClasses = $classes;
|
||||
}
|
||||
|
||||
|
||||
public function getHTMLFragments($grid) {
|
||||
// Check create permission
|
||||
$singleton = singleton($grid->getModelClass());
|
||||
|
@ -89,7 +89,7 @@ class UserForm extends Form {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the form actions for the UserDefinedForm. You
|
||||
* Generate the form actions for the UserDefinedForm. You
|
||||
* can manipulate these by using {@link updateFormActions()} on
|
||||
* a decorator.
|
||||
*
|
||||
|
@ -42,7 +42,7 @@ class EditableCustomRule extends DataObject {
|
||||
|
||||
/**
|
||||
* Publish this custom rule to the live site
|
||||
*
|
||||
*
|
||||
* Wrapper for the {@link Versioned} publish function
|
||||
*/
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
class UserDefinedForm extends Page {
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -37,7 +37,7 @@ class UserDefinedForm extends Page {
|
||||
private static $extensions = array(
|
||||
'UserFormFieldEditorExtension'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @var array Fields on the user defined form page.
|
||||
*/
|
||||
@ -53,10 +53,10 @@ class UserDefinedForm extends Page {
|
||||
'DisableAuthenicatedFinishAction' => 'Boolean',
|
||||
'DisableCsrfSecurityToken' => 'Boolean'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @var array Default values of variables when this page is created
|
||||
*/
|
||||
*/
|
||||
private static $defaults = array(
|
||||
'Content' => '$UserDefinedForm',
|
||||
'DisableSaveSubmissions' => 0,
|
||||
@ -99,34 +99,34 @@ class UserDefinedForm extends Page {
|
||||
*/
|
||||
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',
|
||||
@ -138,22 +138,22 @@ class UserDefinedForm extends Page {
|
||||
->getConfig()
|
||||
->getComponentByType('GridFieldDetailForm')
|
||||
->setItemRequestClass('UserFormRecipientItemRequest');
|
||||
|
||||
|
||||
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
|
||||
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
|
||||
$fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
|
||||
|
||||
|
||||
|
||||
|
||||
// view the submissions
|
||||
$submissions = new GridField(
|
||||
'Submissions',
|
||||
'Submissions',
|
||||
_t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
|
||||
$self->Submissions()->sort('Created', 'DESC')
|
||||
);
|
||||
|
||||
|
||||
// make sure a numeric not a empty string is checked against this int column for SQL server
|
||||
$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
|
||||
SELECT "Name", "Title"
|
||||
@ -167,7 +167,7 @@ SQL;
|
||||
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());
|
||||
@ -181,39 +181,39 @@ SQL;
|
||||
$config->addComponent(new GridFieldButtonRow('after'));
|
||||
$config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
|
||||
$config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
// attach every column to the print view form
|
||||
$columns['Created'] = 'Created';
|
||||
$filter->setColumns($columns);
|
||||
|
||||
|
||||
// print configuration
|
||||
|
||||
|
||||
$print->setPrintHasHeader(true);
|
||||
$print->setPrintColumns($columns);
|
||||
|
||||
|
||||
// export configuration
|
||||
$export->setCsvHasHeader(true);
|
||||
$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 = parent::getCMSFields();
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ SQL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom options for the form. You can extend the built in options by
|
||||
* Custom options for the form. You can extend the built in options by
|
||||
* using {@link updateFormOptions()}
|
||||
*
|
||||
* @return FieldList
|
||||
@ -247,7 +247,7 @@ SQL;
|
||||
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),
|
||||
@ -258,9 +258,9 @@ SQL;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ SQL;
|
||||
->create('UserFormsUpgradeService')
|
||||
->setQuiet(true)
|
||||
->run();
|
||||
|
||||
|
||||
DB::alteration_message('Migrated userforms', 'changed');
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ SQL;
|
||||
*/
|
||||
|
||||
class UserDefinedForm_Controller extends Page_Controller {
|
||||
|
||||
|
||||
private static $finished_anchor = '#uff';
|
||||
|
||||
private static $allowed_actions = array(
|
||||
@ -317,7 +317,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
||||
|
||||
// load the jquery
|
||||
$lang = i18n::get_lang_from_locale(i18n::get_locale());
|
||||
Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
|
||||
@ -336,7 +336,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Using $UserDefinedForm in the Content area of the page shows
|
||||
* where the form should be rendered into. If it does not exist
|
||||
@ -444,7 +444,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
break;
|
||||
case 'IsBlank':
|
||||
$expression = ($checkboxField || $radioField) ? '!($(this).is(":checked"))' : '$(this).val() == ""';
|
||||
|
||||
|
||||
break;
|
||||
case 'HasValue':
|
||||
if ($checkboxField) {
|
||||
@ -459,11 +459,11 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
break;
|
||||
case 'ValueLessThan':
|
||||
$expression = '$(this).val() < parseFloat("'. $rule->FieldValue .'")';
|
||||
|
||||
|
||||
break;
|
||||
case 'ValueLessThanEqual':
|
||||
$expression = '$(this).val() <= parseFloat("'. $rule->FieldValue .'")';
|
||||
|
||||
|
||||
break;
|
||||
case 'ValueGreaterThan':
|
||||
$expression = '$(this).val() > parseFloat("'. $rule->FieldValue .'")';
|
||||
@ -502,7 +502,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($watch) {
|
||||
foreach($watch as $key => $values) {
|
||||
$logic = array();
|
||||
@ -614,7 +614,7 @@ JS
|
||||
if(in_array("EditableFileField", $field->getClassAncestry())) {
|
||||
if(isset($_FILES[$field->Name])) {
|
||||
$foldername = $field->getFormField()->getFolderName();
|
||||
|
||||
|
||||
// create the file from post data
|
||||
$upload = new Upload();
|
||||
$file = new File();
|
||||
@ -630,7 +630,7 @@ JS
|
||||
|
||||
// write file to form field
|
||||
$submittedField->UploadedFileID = $file->ID;
|
||||
|
||||
|
||||
// attach a file only if lower than 1MB
|
||||
if($file->getAbsoluteSize() < 1024*1024*1) {
|
||||
$attachments[] = $file;
|
||||
@ -640,7 +640,7 @@ JS
|
||||
}
|
||||
|
||||
$submittedField->extend('onPopulationFromField', $field);
|
||||
|
||||
|
||||
if(!$this->DisableSaveSubmissions) {
|
||||
$submittedField->write();
|
||||
}
|
||||
@ -664,8 +664,8 @@ JS
|
||||
foreach($attachments as $file) {
|
||||
if($file->ID != 0) {
|
||||
$email->attachFile(
|
||||
$file->Filename,
|
||||
$file->Filename,
|
||||
$file->Filename,
|
||||
$file->Filename,
|
||||
HTTP::get_mime_type($file->Filename)
|
||||
);
|
||||
}
|
||||
@ -685,7 +685,7 @@ JS
|
||||
$email->setBody($parsedBody);
|
||||
$email->setTo($recipient->EmailAddress);
|
||||
$email->setSubject($recipient->EmailSubject);
|
||||
|
||||
|
||||
if($recipient->EmailReplyTo) {
|
||||
$email->setReplyTo($recipient->EmailReplyTo);
|
||||
}
|
||||
@ -701,12 +701,12 @@ JS
|
||||
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
||||
if($recipient->SendEmailToField()) {
|
||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
||||
|
||||
|
||||
if($submittedFormField && is_string($submittedFormField->Value)) {
|
||||
$email->setTo($submittedFormField->Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check to see if there is a dynamic subject
|
||||
if($recipient->SendEmailSubjectField()) {
|
||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
|
||||
@ -739,10 +739,10 @@ JS
|
||||
|
||||
Session::clear("FormInfo.{$form->FormName()}.errors");
|
||||
Session::clear("FormInfo.{$form->FormName()}.data");
|
||||
|
||||
|
||||
$referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
|
||||
|
||||
// set a session variable from the security ID to stop people accessing
|
||||
// set a session variable from the security ID to stop people accessing
|
||||
// the finished method directly.
|
||||
if(!$this->DisableAuthenicatedFinishAction) {
|
||||
if (isset($data['SecurityID'])) {
|
||||
@ -783,7 +783,7 @@ JS
|
||||
}
|
||||
|
||||
/**
|
||||
* This action handles rendering the "finished" message, which is
|
||||
* This action handles rendering the "finished" message, which is
|
||||
* customizable by editing the ReceivedFormSubmission template.
|
||||
*
|
||||
* @return ViewableData
|
||||
@ -796,7 +796,7 @@ JS
|
||||
}
|
||||
|
||||
$referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
|
||||
|
||||
|
||||
if(!$this->DisableAuthenicatedFinishAction) {
|
||||
$formProcessed = Session::get('FormProcessed');
|
||||
|
||||
|
@ -3,14 +3,14 @@
|
||||
* EditableCheckbox
|
||||
*
|
||||
* A user modifiable checkbox on a UserDefinedForm
|
||||
*
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableCheckbox extends EditableFormField {
|
||||
|
||||
|
||||
private static $singular_name = 'Checkbox Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Checkboxes';
|
||||
|
||||
private static $db = array(
|
||||
@ -40,10 +40,10 @@ class EditableCheckbox extends EditableFormField {
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
public function getValueFromData($data) {
|
||||
$value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
||||
|
||||
|
||||
return ($value) ? _t('EditableFormField.YES', 'Yes') : _t('EditableFormField.NO', 'No');
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ class EditableCheckbox extends EditableFormField {
|
||||
$this->CheckedDefault = (bool)$data['Default'];
|
||||
unset($data['Default']);
|
||||
}
|
||||
|
||||
|
||||
parent::migrateSettings($data);
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,16 @@
|
||||
* EditableCheckboxGroup
|
||||
*
|
||||
* Represents a set of selectable radio buttons
|
||||
*
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
||||
|
||||
private static $singular_name = "Checkbox Group";
|
||||
|
||||
|
||||
private static $plural_name = "Checkbox Groups";
|
||||
|
||||
|
||||
public function getFormField() {
|
||||
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
||||
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
||||
@ -26,11 +26,11 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
||||
$this->doUpdateFormField($field);
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
public function getValueFromData($data) {
|
||||
$result = '';
|
||||
$entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
||||
|
||||
|
||||
if($entries) {
|
||||
if(!is_array($data[$this->Name])) {
|
||||
$entries = array($data[$this->Name]);
|
||||
|
@ -8,7 +8,7 @@
|
||||
class EditableCountryDropdownField extends EditableFormField {
|
||||
|
||||
private static $singular_name = 'Country Dropdown';
|
||||
|
||||
|
||||
private static $plural_name = 'Country Dropdowns';
|
||||
|
||||
/**
|
||||
@ -21,7 +21,7 @@ class EditableCountryDropdownField extends EditableFormField {
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function getFormField() {
|
||||
$field = CountryDropdownField::create($this->Name, $this->EscapedTitle)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
@ -31,14 +31,14 @@ class EditableCountryDropdownField extends EditableFormField {
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
public function getValueFromData($data) {
|
||||
if(isset($data[$this->Name])) {
|
||||
$source = $this->getFormField()->getSource();
|
||||
return $source[$data[$this->Name]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getIcon() {
|
||||
return USERFORMS_DIR . '/images/editabledropdown.png';
|
||||
}
|
||||
|
@ -8,9 +8,9 @@
|
||||
*/
|
||||
|
||||
class EditableDateField extends EditableFormField {
|
||||
|
||||
|
||||
private static $singular_name = 'Date Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Date Fields';
|
||||
|
||||
private static $db = array(
|
||||
@ -34,7 +34,7 @@ class EditableDateField extends EditableFormField {
|
||||
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the form field
|
||||
*
|
||||
|
@ -8,9 +8,9 @@
|
||||
*/
|
||||
|
||||
class EditableDropdown extends EditableMultipleOptionField {
|
||||
|
||||
|
||||
private static $singular_name = 'Dropdown Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Dropdowns';
|
||||
|
||||
/**
|
||||
@ -23,7 +23,7 @@ class EditableDropdown extends EditableMultipleOptionField {
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return DropdownField
|
||||
*/
|
||||
|
@ -8,15 +8,15 @@
|
||||
*/
|
||||
|
||||
class EditableEmailField extends EditableFormField {
|
||||
|
||||
|
||||
private static $singular_name = 'Email Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Email Fields';
|
||||
|
||||
|
||||
public function getSetsOwnError() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function getFormField() {
|
||||
$field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
@ -26,7 +26,7 @@ class EditableEmailField extends EditableFormField {
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates a formfield with the additional metadata specified by this field
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ class EditableFieldGroup extends EditableFormField {
|
||||
$title = $this->getFieldNumber()
|
||||
?: $this->Title
|
||||
?: 'group';
|
||||
|
||||
|
||||
return _t(
|
||||
'EditableFieldGroupEnd.FIELD_GROUP_START',
|
||||
'Group {group}',
|
||||
@ -66,7 +66,7 @@ class EditableFieldGroup extends EditableFormField {
|
||||
// Since this field expects raw html, safely escape the user data prior
|
||||
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
||||
}
|
||||
|
||||
|
||||
// if this field has an extra class
|
||||
if($this->ExtraClass) {
|
||||
$field->addExtraClass($this->ExtraClass);
|
||||
@ -88,5 +88,5 @@ class EditableFieldGroup extends EditableFormField {
|
||||
$end->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
* @var bool
|
||||
*/
|
||||
private static $hidden = true;
|
||||
|
||||
|
||||
/**
|
||||
* Non-data type
|
||||
*
|
||||
@ -73,7 +73,7 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
->where('"EditableFieldGroup"."EndID" IS NULL OR "EditableFieldGroup"."EndID" = 0')
|
||||
->sort('"Sort" DESC')
|
||||
->first();
|
||||
|
||||
|
||||
// When a group is found, attach it to this end
|
||||
if($group) {
|
||||
$group->EndID = $this->ID;
|
||||
@ -90,5 +90,5 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,9 +7,9 @@
|
||||
*/
|
||||
|
||||
class EditableFileField extends EditableFormField {
|
||||
|
||||
|
||||
private static $singular_name = 'File Upload Field';
|
||||
|
||||
|
||||
private static $plural_names = 'File Fields';
|
||||
|
||||
private static $has_one = array(
|
||||
@ -30,7 +30,7 @@ class EditableFileField extends EditableFormField {
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
TreeDropdownField::create(
|
||||
@ -40,8 +40,8 @@ class EditableFileField extends EditableFormField {
|
||||
)
|
||||
);
|
||||
|
||||
$fields->addFieldToTab("Root.Main", new LiteralField("FileUploadWarning",
|
||||
"<p class=\"message notice\">" . _t("UserDefinedForm.FileUploadWarning",
|
||||
$fields->addFieldToTab("Root.Main", new LiteralField("FileUploadWarning",
|
||||
"<p class=\"message notice\">" . _t("UserDefinedForm.FileUploadWarning",
|
||||
"Files uploaded through this field could be publicly accessible if the exact URL is known")
|
||||
. "</p>"), "Type");
|
||||
|
||||
@ -72,8 +72,8 @@ class EditableFileField extends EditableFormField {
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the value for the database, link to the file is stored as a
|
||||
* relation so value for the field can be null.
|
||||
@ -83,7 +83,7 @@ class EditableFileField extends EditableFormField {
|
||||
public function getValueFromData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function getSubmittedFormField() {
|
||||
return new SubmittedFileField();
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ class EditableFormField extends DataObject {
|
||||
if(!$form || !$form->exists() || !($fields = $form->Fields())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$prior = 0; // Number of prior group at this level
|
||||
$stack = array(); // Current stack of nested groups, where the top level = the page
|
||||
foreach($fields->map('ID', 'ClassName') as $id => $className) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
class EditableFormHeading extends EditableFormField {
|
||||
|
||||
private static $singular_name = 'Heading';
|
||||
|
||||
|
||||
private static $plural_name = 'Headings';
|
||||
|
||||
private static $literal = true;
|
||||
@ -39,7 +39,7 @@ class EditableFormHeading extends EditableFormField {
|
||||
'5' => '5',
|
||||
'6' => '6'
|
||||
);
|
||||
|
||||
|
||||
$fields->addFieldsToTab('Root.Main', array(
|
||||
DropdownField::create(
|
||||
'Level',
|
||||
@ -74,11 +74,11 @@ class EditableFormHeading extends EditableFormField {
|
||||
$field->addExtraClass($this->ExtraClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function showInReports() {
|
||||
return !$this->HideFromReports;
|
||||
}
|
||||
|
||||
|
||||
public function getFieldValidationOptions() {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,14 +3,14 @@
|
||||
/**
|
||||
* Editable Literal Field. A literal field is just a blank slate where
|
||||
* you can add your own HTML / Images / Flash
|
||||
*
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableLiteralField extends EditableFormField {
|
||||
|
||||
|
||||
private static $singular_name = 'HTML Block';
|
||||
|
||||
|
||||
private static $plural_name = 'HTML Blocks';
|
||||
|
||||
/**
|
||||
@ -118,7 +118,7 @@ class EditableLiteralField extends EditableFormField {
|
||||
} else {
|
||||
$label = "<label class='left'>{$this->EscapedTitle}</label>";
|
||||
}
|
||||
|
||||
|
||||
$field = new LiteralField(
|
||||
"LiteralField[{$this->ID}]",
|
||||
sprintf(
|
||||
@ -136,7 +136,7 @@ class EditableLiteralField extends EditableFormField {
|
||||
// When dealing with literal fields there is no further customisation that can be added at this point
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
public function showInReports() {
|
||||
return ! $this->HideFromReports;
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
*/
|
||||
|
||||
class EditableMemberListField extends EditableFormField {
|
||||
|
||||
|
||||
private static $singular_name = 'Member List Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Member List Fields';
|
||||
|
||||
private static $has_one = array(
|
||||
@ -23,7 +23,7 @@ class EditableMemberListField extends EditableFormField {
|
||||
|
||||
$fields->removeByName('Default');
|
||||
$fields->removeByName('Validation');
|
||||
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
DropdownField::create(
|
||||
@ -35,25 +35,25 @@ class EditableMemberListField extends EditableFormField {
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function getFormField() {
|
||||
if(empty($this->GroupID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$members = Member::map_in_groups($this->GroupID);
|
||||
$field = new DropdownField($this->Name, $this->EscapedTitle, $members);
|
||||
$this->doUpdateFormField($field);
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
public function getValueFromData($data) {
|
||||
if(isset($data[$this->Name])) {
|
||||
$memberID = $data[$this->Name];
|
||||
$member = Member::get()->byID($memberID);
|
||||
return $member ? $member->getName() : "";
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base class for multiple option fields such as {@link EditableDropdownField}
|
||||
* and radio sets.
|
||||
*
|
||||
* Implemented as a class but should be viewed as abstract, you should
|
||||
* Base class for multiple option fields such as {@link EditableDropdownField}
|
||||
* and radio sets.
|
||||
*
|
||||
* Implemented as a class but should be viewed as abstract, you should
|
||||
* instantiate a subclass such as {@link EditableDropdownField}
|
||||
*
|
||||
* @see EditableCheckboxGroupField
|
||||
@ -22,7 +22,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
* @var bool
|
||||
*/
|
||||
private static $abstract = true;
|
||||
|
||||
|
||||
private static $has_many = array(
|
||||
"Options" => "EditableOption"
|
||||
);
|
||||
@ -48,7 +48,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
}
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
$optionsConfig = GridFieldConfig::create()
|
||||
->addComponents(
|
||||
new GridFieldToolbarHeader(),
|
||||
@ -71,13 +71,13 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Publishing Versioning support.
|
||||
*
|
||||
* When publishing it needs to handle copying across / publishing
|
||||
* each of the individual field options
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
@ -88,19 +88,19 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
$option->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($this->Options()) {
|
||||
foreach($this->Options() as $option) {
|
||||
$option->publish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unpublishing Versioning support
|
||||
*
|
||||
*
|
||||
* When unpublishing the field it has to remove all options attached
|
||||
*
|
||||
* @return void
|
||||
@ -111,12 +111,12 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
$option->deleteFromStage($stage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->deleteFromStage($stage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes all the options attached to this field before deleting the
|
||||
* Deletes all the options attached to this field before deleting the
|
||||
* field. Keeps stray options from floating around
|
||||
*
|
||||
* @return void
|
||||
@ -129,31 +129,31 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
$option->delete();
|
||||
}
|
||||
}
|
||||
|
||||
parent::delete();
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplicate a pages content. We need to make sure all the fields attached
|
||||
* Duplicate a pages content. We need to make sure all the fields attached
|
||||
* to that page go with it
|
||||
*
|
||||
*
|
||||
* @return DataObject
|
||||
*/
|
||||
public function duplicate($doWrite = true) {
|
||||
$clonedNode = parent::duplicate();
|
||||
|
||||
|
||||
foreach($this->Options() as $field) {
|
||||
$newField = $field->duplicate(false);
|
||||
$newField->ParentID = $clonedNode->ID;
|
||||
$newField->Version = 0;
|
||||
$newField->write();
|
||||
}
|
||||
|
||||
|
||||
return $clonedNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whether or not this field has addable options such as a
|
||||
* Return whether or not this field has addable options such as a
|
||||
* {@link EditableDropdownField} or {@link EditableRadioField}
|
||||
*
|
||||
* @return bool
|
||||
|
@ -10,18 +10,18 @@
|
||||
class EditableNumericField extends EditableFormField {
|
||||
|
||||
private static $singular_name = 'Numeric Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Numeric Fields';
|
||||
|
||||
private static $db = array(
|
||||
'MinValue' => 'Int',
|
||||
'MaxValue' => 'Int'
|
||||
);
|
||||
|
||||
|
||||
public function getSetsOwnError() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return NumericField
|
||||
*/
|
||||
|
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base Class for EditableOption Fields such as the ones used in
|
||||
* Base Class for EditableOption Fields such as the ones used in
|
||||
* dropdown fields and in radio check box groups
|
||||
*
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableOption extends DataObject {
|
||||
|
||||
|
||||
private static $default_sort = "Sort";
|
||||
|
||||
private static $db = array(
|
||||
@ -17,11 +17,11 @@ class EditableOption extends DataObject {
|
||||
"Default" => "Boolean",
|
||||
"Sort" => "Int"
|
||||
);
|
||||
|
||||
|
||||
private static $has_one = array(
|
||||
"Parent" => "EditableMultipleOptionField",
|
||||
);
|
||||
|
||||
|
||||
private static $extensions = array(
|
||||
"Versioned('Stage', 'Live')"
|
||||
);
|
||||
|
@ -8,9 +8,9 @@
|
||||
*/
|
||||
|
||||
class EditableRadioField extends EditableMultipleOptionField {
|
||||
|
||||
|
||||
private static $singular_name = 'Radio Group';
|
||||
|
||||
|
||||
private static $plural_name = 'Radio Groups';
|
||||
|
||||
/**
|
||||
@ -23,7 +23,7 @@ class EditableRadioField extends EditableMultipleOptionField {
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function getFormField() {
|
||||
$field = OptionsetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
||||
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
||||
|
@ -10,7 +10,7 @@
|
||||
class EditableTextField extends EditableFormField {
|
||||
|
||||
private static $singular_name = 'Text Field';
|
||||
|
||||
|
||||
private static $plural_name = 'Text Fields';
|
||||
|
||||
private static $db = array(
|
||||
|
@ -113,7 +113,7 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
Requirements::javascript(USERFORMS_DIR . '/javascript/Recipient.js');
|
||||
|
||||
|
||||
// Determine optional field values
|
||||
$form = $this->getFormParent();
|
||||
|
||||
|
@ -1,39 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A file uploaded on a {@link UserDefinedForm} and attached to a single
|
||||
* A file uploaded on a {@link UserDefinedForm} and attached to a single
|
||||
* {@link SubmittedForm}.
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class SubmittedFileField extends SubmittedFormField {
|
||||
|
||||
|
||||
private static $has_one = array(
|
||||
"UploadedFile" => "File"
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Return the value of this field for inclusion into things such as
|
||||
* Return the value of this field for inclusion into things such as
|
||||
* reports.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedValue() {
|
||||
$name = $this->getFileName();
|
||||
$link = $this->getLink();
|
||||
$title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
|
||||
|
||||
|
||||
if($link) {
|
||||
return DBField::create_field('HTMLText', sprintf(
|
||||
'%s - <a href="%s" target="_blank">%s</a>',
|
||||
'%s - <a href="%s" target="_blank">%s</a>',
|
||||
$name, $link, $title
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the value for this field in the CSV export.
|
||||
*
|
||||
@ -45,7 +45,7 @@ class SubmittedFileField extends SubmittedFormField {
|
||||
|
||||
/**
|
||||
* Return the link for the file attached to this submitted form field.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLink() {
|
||||
@ -55,7 +55,7 @@ class SubmittedFileField extends SubmittedFormField {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the file, if present
|
||||
*
|
||||
|
@ -6,13 +6,13 @@
|
||||
*/
|
||||
|
||||
class SubmittedForm extends DataObject {
|
||||
|
||||
|
||||
private static $has_one = array(
|
||||
"SubmittedBy" => "Member",
|
||||
"Parent" => "UserDefinedForm",
|
||||
);
|
||||
|
||||
private static $has_many = array(
|
||||
|
||||
private static $has_many = array(
|
||||
"Values" => "SubmittedFormField"
|
||||
);
|
||||
|
||||
@ -20,13 +20,13 @@ class SubmittedForm extends DataObject {
|
||||
'ID',
|
||||
'Created'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value of a relation or, in the case of this form, the value
|
||||
* of a given child {@link SubmittedFormField}
|
||||
*
|
||||
*
|
||||
* @param string
|
||||
*
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function relField($fieldName) {
|
||||
@ -50,30 +50,30 @@ class SubmittedForm extends DataObject {
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
|
||||
|
||||
$self = $this;
|
||||
|
||||
|
||||
$this->beforeUpdateCMSFields(function($fields) use ($self) {
|
||||
$fields->removeByName('Values');
|
||||
$fields->dataFieldByName('SubmittedByID')->setDisabled(true);
|
||||
|
||||
|
||||
$values = new GridField(
|
||||
'Values',
|
||||
'Values',
|
||||
'SubmittedFormField',
|
||||
$self->Values()->sort('Created', 'ASC')
|
||||
);
|
||||
|
||||
|
||||
$config = new GridFieldConfig();
|
||||
$config->addComponent(new GridFieldDataColumns());
|
||||
$config->addComponent(new GridFieldExportButton());
|
||||
$config->addComponent(new GridFieldPrintButton());
|
||||
$values->setConfig($config);
|
||||
|
||||
|
||||
$fields->addFieldToTab('Root.Main', $values);
|
||||
});
|
||||
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ class SubmittedForm extends DataObject {
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
parent::onBeforeDelete();
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
*/
|
||||
|
||||
class SubmittedFormField extends DataObject {
|
||||
|
||||
|
||||
private static $db = array(
|
||||
"Name" => "Varchar",
|
||||
"Value" => "Text",
|
||||
"Title" => "Varchar(255)"
|
||||
);
|
||||
|
||||
|
||||
private static $has_one = array(
|
||||
"Parent" => "SubmittedForm"
|
||||
);
|
||||
@ -68,7 +68,7 @@ class SubmittedFormField extends DataObject {
|
||||
public function getFormattedValue() {
|
||||
return nl2br($this->dbObject('Value')->ATT());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the value of this submitted form field suitable for inclusion
|
||||
* into the CSV
|
||||
@ -84,7 +84,7 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* Note the field may have been modified or deleted from the original form
|
||||
* so this may not always return the data you expect. If you need to save
|
||||
* a particular state of editable form field at time of submission, copy
|
||||
* a particular state of editable form field at time of submission, copy
|
||||
* that value to the submission.
|
||||
*
|
||||
* @return EditableFormField
|
||||
|
@ -56,7 +56,7 @@ class UserFormsUpgradeService {
|
||||
|
||||
// Migrate custom settings
|
||||
$this->migrateCustomSettings($field, $stage);
|
||||
|
||||
|
||||
// Flag as migrated
|
||||
$field->Migrated = true;
|
||||
$field->write();
|
||||
@ -214,5 +214,5 @@ class UserFormsUpgradeService {
|
||||
public function getQuiet() {
|
||||
return $this->quiet;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ class UserFormsVersionedTask extends MigrationTask {
|
||||
protected $title = "UserForms Versioned Initial Migration";
|
||||
|
||||
protected $description = "Publishes the existing forms";
|
||||
|
||||
|
||||
/**
|
||||
* Publish the existing forms.
|
||||
*
|
||||
*/
|
||||
public function run($request) {
|
||||
$forms = Versioned::get_by_stage('UserDefinedForm', 'Live');
|
||||
|
||||
|
||||
if($forms) {
|
||||
foreach($forms as $form) {
|
||||
echo "Publishing $form->Title <br />";
|
||||
|
@ -5,37 +5,37 @@
|
||||
*/
|
||||
|
||||
class EditableFormFieldTest extends FunctionalTest {
|
||||
|
||||
|
||||
static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
|
||||
|
||||
|
||||
function testFormFieldPermissions() {
|
||||
$text = $this->objFromFixture('EditableTextField', 'basic-text');
|
||||
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$this->assertTrue($text->canEdit());
|
||||
$this->assertTrue($text->canDelete());
|
||||
|
||||
|
||||
$text->setReadonly(true);
|
||||
$this->assertFalse($text->canEdit());
|
||||
$this->assertFalse($text->canDelete());
|
||||
|
||||
|
||||
$text->setReadonly(false);
|
||||
$this->assertTrue($text->canEdit());
|
||||
$this->assertTrue($text->canDelete());
|
||||
|
||||
|
||||
$member = Member::currentUser();
|
||||
$member->logout();
|
||||
|
||||
|
||||
$this->logInWithPermission('SITETREE_VIEW_ALL');
|
||||
$text->setReadonly(false);
|
||||
$this->assertFalse($text->canEdit());
|
||||
$this->assertFalse($text->canDelete());
|
||||
|
||||
|
||||
$text->setReadonly(true);
|
||||
$this->assertFalse($text->canEdit());
|
||||
$this->assertFalse($text->canDelete());
|
||||
}
|
||||
|
||||
|
||||
function testCustomRules() {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
|
||||
@ -56,40 +56,40 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertEquals($checkboxRule->ConditionOption, 'HasValue');
|
||||
$this->assertEquals($checkboxRule->FieldValue, '6');
|
||||
}
|
||||
|
||||
|
||||
function testEditableDropdownField() {
|
||||
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
|
||||
|
||||
|
||||
$field = $dropdown->getFormField();
|
||||
|
||||
|
||||
|
||||
|
||||
$this->assertThat($field, $this->isInstanceOf('DropdownField'));
|
||||
$values = $field->getSource();
|
||||
|
||||
|
||||
$this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
|
||||
}
|
||||
|
||||
|
||||
function testEditableRadioField() {
|
||||
$radio = $this->objFromFixture('EditableRadioField', 'radio-field');
|
||||
|
||||
|
||||
$field = $radio->getFormField();
|
||||
|
||||
|
||||
$this->assertThat($field, $this->isInstanceOf('OptionsetField'));
|
||||
$values = $field->getSource();
|
||||
|
||||
|
||||
$this->assertEquals(array('Option 5' => 'Option 5', 'Option 6' => 'Option 6'), $values);
|
||||
}
|
||||
|
||||
|
||||
function testMultipleOptionDuplication() {
|
||||
$dropdown = $this->objFromFixture('EditableDropdown','basic-dropdown');
|
||||
|
||||
|
||||
$clone = $dropdown->duplicate();
|
||||
|
||||
$this->assertEquals($clone->Options()->Count(), $dropdown->Options()->Count());
|
||||
|
||||
|
||||
foreach($clone->Options() as $option) {
|
||||
$orginal = $dropdown->Options()->find('Title', $option->Title);
|
||||
|
||||
|
||||
$this->assertEquals($orginal->Sort, $option->Sort);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class EditableLiteralFieldTest extends SapphireTest {
|
||||
$rawContent = '<h1>Welcome</h1><script>alert("Hello!");</script><p>Giant Robots!</p>';
|
||||
$safeContent = '<h1>Welcome</h1><p>Giant Robots!</p>';
|
||||
$field = new EditableLiteralField();
|
||||
|
||||
|
||||
// Test with sanitisation enabled
|
||||
Config::inst()->update('HtmlEditorField', 'sanitise_server_side', true);
|
||||
$field->setContent($rawContent);
|
||||
|
@ -11,7 +11,7 @@ class SecureEditableFileFieldTest extends SapphireTest {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
||||
if(!class_exists('SecureFileExtension')) {
|
||||
$this->skipTest = true;
|
||||
$this->markTestSkipped(get_class() . ' skipped unless running with securefiles');
|
||||
|
@ -5,14 +5,14 @@
|
||||
*/
|
||||
|
||||
class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
|
||||
|
||||
static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
||||
function testProcess() {
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
|
||||
|
||||
$this->autoFollowRedirection = false;
|
||||
$this->clearEmails();
|
||||
|
||||
@ -26,40 +26,40 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
// should have a submitted form field now
|
||||
$submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
|
||||
$this->assertDOSAllMatch(array('Name' => 'basic-text-name', 'Value' => 'Basic Value', 'Title' => 'Basic Text Field'), $submitted);
|
||||
|
||||
|
||||
// check emails
|
||||
$this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$email = $this->findEmail('test@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
|
||||
|
||||
// assert that the email has the field title and the value html email
|
||||
$parser = new CSSContentParser($email['content']);
|
||||
$title = $parser->getBySelector('strong');
|
||||
|
||||
|
||||
$this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
|
||||
|
||||
|
||||
$value = $parser->getBySelector('dd');
|
||||
$this->assertEquals('Basic Value', (string) $value[0], 'Email contains the value');
|
||||
|
||||
|
||||
// no html
|
||||
$this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$nohtml = $this->findEmail('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
|
||||
$this->assertContains('Basic Text Field: Basic Value', $nohtml['content'], 'Email contains no html');
|
||||
|
||||
|
||||
// no data
|
||||
$this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
$nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||
|
||||
|
||||
$parser = new CSSContentParser($nodata['content']);
|
||||
$list = $parser->getBySelector('dl');
|
||||
|
||||
|
||||
$this->assertFalse(isset($list[0]), 'Email contains no fields');
|
||||
|
||||
|
||||
// check to see if the user was redirected (301)
|
||||
$this->assertEquals($response->getStatusCode(), 302);
|
||||
$this->assertStringEndsWith('finished#uff', $response->getHeader('Location'));
|
||||
}
|
||||
|
||||
|
||||
function testFinished() {
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
@ -68,7 +68,7 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->session()->inst_set('FormProcessed', 1);
|
||||
|
||||
$response = $this->get($form->URLSegment.'/finished');
|
||||
|
||||
|
||||
$this->assertContains($form->OnCompleteMessage ,$response->getBody());
|
||||
}
|
||||
|
||||
@ -80,16 +80,16 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->session()->inst_set('FormProcessed', null);
|
||||
|
||||
$response = $this->get($form->URLSegment.'/finished');
|
||||
|
||||
|
||||
$this->assertNotContains($form->OnCompleteMessage ,$response->getBody());
|
||||
}
|
||||
|
||||
|
||||
function testForm() {
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
|
||||
// test form
|
||||
|
||||
// test form
|
||||
$this->assertEquals($controller->Form()->getName(), 'Form', 'The form is referenced as Form');
|
||||
$this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
|
||||
$this->assertEquals($controller->Form()->Actions()->Count(), 1);
|
||||
@ -102,23 +102,23 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->assertEquals($controller->Form()->Actions()->Count(), 1);
|
||||
$this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
|
||||
}
|
||||
|
||||
|
||||
function testGetFormFields() {
|
||||
// generating the fieldset of fields
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
|
||||
|
||||
$formSteps = $controller->Form()->getFormFields();
|
||||
$firstStep = $formSteps->first();
|
||||
|
||||
$this->assertEquals($formSteps->Count(), 1);
|
||||
$this->assertEquals($firstStep->getChildren()->Count(), 1);
|
||||
|
||||
|
||||
// custom error message on a form field
|
||||
$requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
|
||||
$controller = new UserDefinedFormControllerTest_Controller($requiredForm);
|
||||
|
||||
|
||||
UserDefinedForm::config()->required_identifier = "*";
|
||||
|
||||
$formSteps = $controller->Form()->getFormFields();
|
||||
@ -127,37 +127,37 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
|
||||
$this->assertEquals('Custom Error Message', $firstField->getCustomValidationMessage()->getValue());
|
||||
$this->assertEquals($firstField->Title(), 'Required Text Field <span class=\'required-identifier\'>*</span>');
|
||||
|
||||
|
||||
// test custom right title
|
||||
$field = $form->Fields()->limit(1, 1)->First();
|
||||
$field->RightTitle = 'Right Title';
|
||||
$field->write();
|
||||
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
$formSteps = $controller->Form()->getFormFields();
|
||||
$firstStep = $formSteps->first();
|
||||
|
||||
$this->assertEquals($firstStep->getChildren()->First()->RightTitle(), "Right Title");
|
||||
|
||||
|
||||
// test empty form
|
||||
$emptyForm = $this->objFromFixture('UserDefinedForm', 'empty-form');
|
||||
$controller = new UserDefinedFormControllerTest_Controller($emptyForm);
|
||||
|
||||
$this->assertFalse($controller->Form()->getFormFields()->exists());
|
||||
}
|
||||
|
||||
|
||||
function testGetFormActions() {
|
||||
// generating the fieldset of actions
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
$actions = $controller->Form()->getFormActions();
|
||||
|
||||
|
||||
// by default will have 1 submit button which links to process
|
||||
$expected = new FieldList(new FormAction('process', 'Submit'));
|
||||
|
||||
|
||||
$this->assertEquals($actions, $expected);
|
||||
|
||||
|
||||
// the custom popup should have a reset button and a custom text
|
||||
$custom = $this->objFromFixture('UserDefinedForm', 'form-with-reset-and-custom-action');
|
||||
$controller = new UserDefinedFormControllerTest_Controller($custom);
|
||||
@ -168,77 +168,77 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
|
||||
$this->assertEquals($actions, $expected);
|
||||
}
|
||||
|
||||
|
||||
function testRenderingIntoFormTemplate() {
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
|
||||
$form->Content = 'This is some content without a form nested between it';
|
||||
$form->doPublish();
|
||||
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
|
||||
|
||||
// check to see if $Form is replaced to inside the content
|
||||
$index = new ArrayData($controller->index());
|
||||
$parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
|
||||
|
||||
$this->checkTemplateIsCorrect($parser);
|
||||
}
|
||||
|
||||
|
||||
function testRenderingIntoTemplateWithSubstringReplacement() {
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
|
||||
|
||||
// check to see if $Form is replaced to inside the content
|
||||
$index = new ArrayData($controller->index());
|
||||
$parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
|
||||
|
||||
|
||||
$this->checkTemplateIsCorrect($parser);
|
||||
}
|
||||
|
||||
|
||||
function setupFormFrontend() {
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
|
||||
$form->doPublish();
|
||||
|
||||
$member = Member::currentUser();
|
||||
$member->logOut();
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
function checkTemplateIsCorrect($parser) {
|
||||
$this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form'));
|
||||
|
||||
|
||||
// check for the input
|
||||
$this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
|
||||
|
||||
|
||||
// check for the label and the text
|
||||
$label = $parser->getBySelector('label.left');
|
||||
$this->assertArrayHasKey(0, $label);
|
||||
|
||||
|
||||
$this->assertEquals((string) $label[0][0], "Basic Text Field", "Label contains correct field name");
|
||||
|
||||
|
||||
// check for the action
|
||||
$action = $parser->getBySelector('input.action');
|
||||
$this->assertArrayHasKey(0, $action);
|
||||
|
||||
|
||||
$this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
|
||||
}
|
||||
}
|
||||
|
||||
class UserDefinedFormControllerTest_Controller extends UserDefinedForM_Controller implements TestOnly {
|
||||
|
||||
|
||||
/**
|
||||
* Overloaded to avoid inconsistencies between 2.4.2 and 2.4.3 (disables all security tokens in unit tests by default)
|
||||
*/
|
||||
function Form() {
|
||||
$form = parent::Form();
|
||||
|
||||
|
||||
if($form) $form->disableSecurityToken();
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
* @package userforms
|
||||
*/
|
||||
class UserDefinedFormTest extends FunctionalTest {
|
||||
|
||||
|
||||
static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
||||
|
||||
public function testRollbackToVersion() {
|
||||
$this->markTestSkipped(
|
||||
'UserDefinedForm::rollback() has not been implemented completely'
|
||||
@ -364,7 +364,7 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertFalse($result->isError());
|
||||
$this->assertContains('<p>Here is my form</p><form', $body);
|
||||
$this->assertContains('</form><p>Thank you for filling it out</p>', $body);
|
||||
|
||||
|
||||
$this->assertNotContains('<p>$UserDefinedForm</p>', $body);
|
||||
$this->assertNotContains('<p></p>', $body);
|
||||
$this->assertNotContains('</p><p>Thank you for filling it out</p>', $body);
|
||||
|
@ -121,7 +121,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest {
|
||||
$field1 = $this->objFromFixture('EditableTextField', 'text1');
|
||||
$field2 = $this->objFromFixture('EditableTextField', 'text2');
|
||||
$field3 = $this->objFromFixture('EditableTextField', 'text3');
|
||||
|
||||
|
||||
$this->assertDOSEquals(array(
|
||||
array(
|
||||
'Display' => 'Show',
|
||||
@ -148,7 +148,7 @@ class UserFormsUpgradeServiceTest extends SapphireTest {
|
||||
$group1 = $this->objFromFixture('Group', 'group1');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'form-with-settings');
|
||||
$folder = $this->objFromFixture('Folder', 'folder1');
|
||||
|
||||
|
||||
$this->assertDOSEquals(array(
|
||||
array(
|
||||
'ClassName' => 'EditableTextField',
|
||||
|
Loading…
Reference in New Issue
Block a user