mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
commit
9294734f73
@ -7,7 +7,8 @@
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader
|
||||
{
|
||||
|
||||
/**
|
||||
* A map of name => value of columns from all submissions
|
||||
@ -15,11 +16,13 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
*/
|
||||
protected $columns;
|
||||
|
||||
public function setColumns($columns) {
|
||||
public function setColumns($columns)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||
{
|
||||
if (!$this->checkDataType($gridField->getList())) {
|
||||
return;
|
||||
}
|
||||
@ -35,7 +38,8 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
}
|
||||
|
||||
|
||||
public function getHTMLFragments($gridField) {
|
||||
public function getHTMLFragments($gridField)
|
||||
{
|
||||
$fields = new ArrayList();
|
||||
$state = $gridField->State->UserFormsGridField;
|
||||
|
||||
@ -108,7 +112,8 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
||||
);
|
||||
}
|
||||
|
||||
public function getManipulatedData(GridField $gridField, SS_List $dataList) {
|
||||
public function getManipulatedData(GridField $gridField, SS_List $dataList)
|
||||
{
|
||||
$state = $gridField->State;
|
||||
|
||||
if ($filter = $state->UserFormsGridField->toArray()) {
|
||||
|
@ -5,7 +5,8 @@
|
||||
*
|
||||
* {@see EditableFileField}
|
||||
*/
|
||||
class SecureEditableFileField extends DataExtension {
|
||||
class SecureEditableFileField extends DataExtension
|
||||
{
|
||||
|
||||
/**
|
||||
* Path to secure files location under assets
|
||||
@ -28,7 +29,8 @@ class SecureEditableFileField extends DataExtension {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsSecurityEnabled() {
|
||||
public function getIsSecurityEnabled()
|
||||
{
|
||||
// Skip if requested
|
||||
if ($this->owner->config()->disable_security) {
|
||||
return false;
|
||||
@ -43,7 +45,8 @@ class SecureEditableFileField extends DataExtension {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function requireDefaultRecords() {
|
||||
public function requireDefaultRecords()
|
||||
{
|
||||
// Skip if disabled
|
||||
if (!$this->getIsSecurityEnabled()) {
|
||||
return;
|
||||
@ -68,14 +71,16 @@ class SecureEditableFileField extends DataExtension {
|
||||
/**
|
||||
* Secure this field before saving
|
||||
*/
|
||||
public function onBeforeWrite() {
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
$this->makeSecure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure this field is secured, but does not write changes to the database
|
||||
*/
|
||||
public function makeSecure() {
|
||||
public function makeSecure()
|
||||
{
|
||||
// Skip if disabled or already secure
|
||||
if (!$this->getIsSecurityEnabled() || $this->owner->getIsSecure()) {
|
||||
return;
|
||||
@ -87,7 +92,6 @@ class SecureEditableFileField extends DataExtension {
|
||||
// Create new folder in default location
|
||||
$folder = Folder::find_or_make($this->owner->config()->secure_folder_name);
|
||||
$this->owner->FolderID = $folder->ID;
|
||||
|
||||
} elseif ($this->isFolderSecured($folder)) {
|
||||
// If folder exists and is secure stop
|
||||
return;
|
||||
@ -104,7 +108,8 @@ class SecureEditableFileField extends DataExtension {
|
||||
*
|
||||
* @return Group
|
||||
*/
|
||||
protected function findAdminGroup() {
|
||||
protected function findAdminGroup()
|
||||
{
|
||||
singleton('Group')->requireDefaultRecords();
|
||||
return Permission::get_groups_by_permission('ADMIN')->First();
|
||||
}
|
||||
@ -114,7 +119,8 @@ class SecureEditableFileField extends DataExtension {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsSecure() {
|
||||
public function getIsSecure()
|
||||
{
|
||||
return $this->isFolderSecured($this->owner->Folder());
|
||||
}
|
||||
|
||||
@ -124,7 +130,8 @@ class SecureEditableFileField extends DataExtension {
|
||||
* @param Folder $folder
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isFolderSecured($folder) {
|
||||
protected function isFolderSecured($folder)
|
||||
{
|
||||
if (! ($folder instanceof Folder) || !$folder->exists()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
class UserFormFieldEditorExtension extends DataExtension {
|
||||
class UserFormFieldEditorExtension extends DataExtension
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@ -17,7 +18,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function updateCMSFields(FieldList $fields) {
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
$fieldEditor = $this->getFieldEditorGrid();
|
||||
|
||||
$fields->insertAfter(new Tab('FormFields', _t('UserFormFieldEditorExtension.FORMFIELDS', 'Form Fields')), 'Main');
|
||||
@ -31,7 +33,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return GridField
|
||||
*/
|
||||
public function getFieldEditorGrid() {
|
||||
public function getFieldEditorGrid()
|
||||
{
|
||||
Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
|
||||
|
||||
$fields = $this->owner->Fields();
|
||||
@ -88,7 +91,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
* @param bool $force
|
||||
* @return void
|
||||
*/
|
||||
public function createInitialFormStep($force = false) {
|
||||
public function createInitialFormStep($force = false)
|
||||
{
|
||||
// Only invoke once saved
|
||||
if (!$this->owner->exists()) {
|
||||
return;
|
||||
@ -125,7 +129,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
/**
|
||||
* Ensure that at least one page exists at the start
|
||||
*/
|
||||
public function onAfterWrite() {
|
||||
public function onAfterWrite()
|
||||
{
|
||||
$this->createInitialFormStep();
|
||||
}
|
||||
|
||||
@ -135,7 +140,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterPublish($original) {
|
||||
public function onAfterPublish($original)
|
||||
{
|
||||
// Remove fields on the live table which could have been orphaned.
|
||||
$live = Versioned::get_by_stage("EditableFormField", "Live")
|
||||
->filter('ParentID', $original->ID);
|
||||
@ -157,7 +163,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterUnpublish($page) {
|
||||
public function onAfterUnpublish($page)
|
||||
{
|
||||
foreach ($page->Fields() as $field) {
|
||||
$field->doDeleteFromStage('Live');
|
||||
}
|
||||
@ -169,7 +176,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return DataObject
|
||||
*/
|
||||
public function onAfterDuplicate($newPage) {
|
||||
public function onAfterDuplicate($newPage)
|
||||
{
|
||||
// List of EditableFieldGroups, where the
|
||||
// key of the array is the ID of the old end group
|
||||
$fieldGroups = array();
|
||||
@ -209,7 +217,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsModifiedOnStage($isModified) {
|
||||
public function getIsModifiedOnStage($isModified)
|
||||
{
|
||||
if (!$isModified) {
|
||||
foreach ($this->owner->Fields() as $field) {
|
||||
if ($field->getIsModifiedOnStage()) {
|
||||
@ -228,7 +237,8 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterRevertToLive($page) {
|
||||
public function onAfterRevertToLive($page)
|
||||
{
|
||||
foreach ($page->Fields() as $field) {
|
||||
$field->publish('Live', 'Stage', false);
|
||||
$field->writeWithoutVersion();
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
class UserFormValidator extends RequiredFields {
|
||||
public function php($data) {
|
||||
class UserFormValidator extends RequiredFields
|
||||
{
|
||||
public function php($data)
|
||||
{
|
||||
if (!parent::php($data)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
class UserFormsCheckboxSetField extends CheckboxSetField {
|
||||
class UserFormsCheckboxSetField extends CheckboxSetField
|
||||
{
|
||||
|
||||
/**
|
||||
* jQuery validate requires that the value of the option does not contain
|
||||
@ -11,7 +12,8 @@ class UserFormsCheckboxSetField extends CheckboxSetField {
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function getOptions() {
|
||||
public function getOptions()
|
||||
{
|
||||
$options = parent::getOptions();
|
||||
|
||||
foreach ($options as $option) {
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Represents a composite field group, which may contain other groups
|
||||
*/
|
||||
abstract class UserFormsCompositeField extends CompositeField implements UserFormsFieldContainer {
|
||||
abstract class UserFormsCompositeField extends CompositeField implements UserFormsFieldContainer
|
||||
{
|
||||
|
||||
/**
|
||||
* Parent field
|
||||
@ -12,16 +13,19 @@ abstract class UserFormsCompositeField extends CompositeField implements UserFor
|
||||
*/
|
||||
protected $parent = null;
|
||||
|
||||
public function getParent() {
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function setParent(UserFormsFieldContainer $parent) {
|
||||
public function setParent(UserFormsFieldContainer $parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function processNext(EditableFormField $field) {
|
||||
public function processNext(EditableFormField $field)
|
||||
{
|
||||
// When we find a step, bubble up to the top
|
||||
if ($field instanceof EditableFormStep) {
|
||||
return $this->getParent()->processNext($field);
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Represents a field container which can iteratively process nested fields, converting it into a fieldset
|
||||
*/
|
||||
interface UserFormsFieldContainer {
|
||||
interface UserFormsFieldContainer
|
||||
{
|
||||
|
||||
/**
|
||||
* Process the next field in the list, returning the container to add the next field to.
|
||||
|
@ -3,9 +3,11 @@
|
||||
/**
|
||||
* A list of formfields which allows for iterative processing of nested composite fields
|
||||
*/
|
||||
class UserFormsFieldList extends FieldList implements UserFormsFieldContainer {
|
||||
class UserFormsFieldList extends FieldList implements UserFormsFieldContainer
|
||||
{
|
||||
|
||||
public function processNext(EditableFormField $field) {
|
||||
public function processNext(EditableFormField $field)
|
||||
{
|
||||
$formField = $field->getFormField();
|
||||
if (!$formField) {
|
||||
return $this;
|
||||
@ -20,24 +22,26 @@ class UserFormsFieldList extends FieldList implements UserFormsFieldContainer {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParent() {
|
||||
public function getParent()
|
||||
{
|
||||
// Field list does not have a parent
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setParent(UserFormsFieldContainer $parent) {
|
||||
public function setParent(UserFormsFieldContainer $parent)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all empty steps
|
||||
*/
|
||||
public function clearEmptySteps() {
|
||||
public function clearEmptySteps()
|
||||
{
|
||||
foreach ($this as $field) {
|
||||
if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
|
||||
$this->remove($field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,19 +3,23 @@
|
||||
/**
|
||||
* Front end composite field for userforms
|
||||
*/
|
||||
class UserFormsGroupField extends UserFormsCompositeField {
|
||||
class UserFormsGroupField extends UserFormsCompositeField
|
||||
{
|
||||
|
||||
public function __construct($children = null) {
|
||||
public function __construct($children = null)
|
||||
{
|
||||
parent::__construct($children);
|
||||
$this->setTag('fieldset');
|
||||
}
|
||||
|
||||
public function getLegend() {
|
||||
public function getLegend()
|
||||
{
|
||||
// Legend defaults to title
|
||||
return parent::getLegend() ?: $this->Title();
|
||||
}
|
||||
|
||||
public function processNext(EditableFormField $field) {
|
||||
public function processNext(EditableFormField $field)
|
||||
{
|
||||
// When ending a group, jump up one level
|
||||
if ($field instanceof EditableFieldGroupEnd) {
|
||||
return $this->getParent();
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Represents a page step in a form, which may contain form fields or other groups
|
||||
*/
|
||||
class UserFormsStepField extends UserFormsCompositeField {
|
||||
class UserFormsStepField extends UserFormsCompositeField
|
||||
{
|
||||
|
||||
private static $casting = array(
|
||||
'StepNumber' => 'Int'
|
||||
@ -18,7 +19,8 @@ class UserFormsStepField extends UserFormsCompositeField {
|
||||
*/
|
||||
protected $number = null;
|
||||
|
||||
public function FieldHolder($properties = array()) {
|
||||
public function FieldHolder($properties = array())
|
||||
{
|
||||
return $this->Field($properties);
|
||||
}
|
||||
|
||||
@ -27,7 +29,8 @@ class UserFormsStepField extends UserFormsCompositeField {
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getStepNumber() {
|
||||
public function getStepNumber()
|
||||
{
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
@ -37,7 +40,8 @@ class UserFormsStepField extends UserFormsCompositeField {
|
||||
* @param type $number
|
||||
* @return $this
|
||||
*/
|
||||
public function setStepNumber($number) {
|
||||
public function setStepNumber($number)
|
||||
{
|
||||
$this->number = $number;
|
||||
return $this;
|
||||
}
|
||||
|
@ -7,9 +7,11 @@
|
||||
* @deprecated since version 4.0
|
||||
* @package userforms
|
||||
*/
|
||||
class UserformsTreeDropdownField extends TreeDropdownField {
|
||||
class UserformsTreeDropdownField extends TreeDropdownField
|
||||
{
|
||||
|
||||
public function __construct($name, $title = null, $sourceObject = 'Group', $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true) {
|
||||
public function __construct($name, $title = null, $sourceObject = 'Group', $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true)
|
||||
{
|
||||
parent::__construct($name, $title, $sourceObject, $keyField, $labelField, $showSearch);
|
||||
|
||||
Deprecation::notice('4.0', __CLASS__ . " is deprecated");
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* A button which allows objects to be created with a specified classname(s)
|
||||
*/
|
||||
class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider, GridField_ActionProvider {
|
||||
class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider, GridField_ActionProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Name of fragment to insert into
|
||||
@ -38,7 +39,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
* If you enter more than one class, each click of the "add" button will create one of each
|
||||
* @param string $targetFragment The fragment to render the button into
|
||||
*/
|
||||
public function __construct($classes, $targetFragment = 'buttons-before-left') {
|
||||
public function __construct($classes, $targetFragment = 'buttons-before-left')
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setClasses($classes);
|
||||
$this->setFragment($targetFragment);
|
||||
@ -50,7 +52,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setButtonName($name) {
|
||||
public function setButtonName($name)
|
||||
{
|
||||
$this->buttonName = $name;
|
||||
return $this;
|
||||
}
|
||||
@ -60,7 +63,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getButtonName() {
|
||||
public function getButtonName()
|
||||
{
|
||||
return $this->buttonName;
|
||||
}
|
||||
|
||||
@ -69,7 +73,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFragment() {
|
||||
public function getFragment()
|
||||
{
|
||||
return $this->targetFragment;
|
||||
}
|
||||
|
||||
@ -79,7 +84,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
* @param string $fragment
|
||||
* @return GridFieldAddNewInlineButton $this
|
||||
*/
|
||||
public function setFragment($fragment) {
|
||||
public function setFragment($fragment)
|
||||
{
|
||||
$this->targetFragment = $fragment;
|
||||
return $this;
|
||||
}
|
||||
@ -89,7 +95,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getButtonClass() {
|
||||
public function getButtonClass()
|
||||
{
|
||||
return $this->buttonClass;
|
||||
}
|
||||
|
||||
@ -99,7 +106,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
* @param string $buttonClass
|
||||
* @return $this
|
||||
*/
|
||||
public function setButtonClass($buttonClass) {
|
||||
public function setButtonClass($buttonClass)
|
||||
{
|
||||
$this->buttonClass = $buttonClass;
|
||||
return $this;
|
||||
}
|
||||
@ -110,7 +118,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClasses() {
|
||||
public function getClasses()
|
||||
{
|
||||
return $this->modelClasses;
|
||||
}
|
||||
|
||||
@ -121,7 +130,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
* @param DataGrid $grid
|
||||
* @return array
|
||||
*/
|
||||
public function getClassesCreate($grid) {
|
||||
public function getClassesCreate($grid)
|
||||
{
|
||||
// Get explicit or fallback class list
|
||||
$classes = $this->getClasses();
|
||||
if (empty($classes) && $grid) {
|
||||
@ -139,14 +149,16 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*
|
||||
* @param array $classes
|
||||
*/
|
||||
public function setClasses($classes) {
|
||||
public function setClasses($classes)
|
||||
{
|
||||
if (!is_array($classes)) {
|
||||
$classes = $classes ? array($classes) : array();
|
||||
}
|
||||
$this->modelClasses = $classes;
|
||||
}
|
||||
|
||||
public function getHTMLFragments($grid) {
|
||||
public function getHTMLFragments($grid)
|
||||
{
|
||||
// Check create permission
|
||||
$singleton = singleton($grid->getModelClass());
|
||||
if (!$singleton->canCreate()) {
|
||||
@ -182,7 +194,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getActions($gridField) {
|
||||
public function getActions($gridField)
|
||||
{
|
||||
return array(
|
||||
$this->getAction()
|
||||
);
|
||||
@ -193,11 +206,13 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getAction() {
|
||||
protected function getAction()
|
||||
{
|
||||
return 'add-classes-' . strtolower(implode('-', $this->getClasses()));
|
||||
}
|
||||
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
|
||||
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
|
||||
{
|
||||
switch (strtolower($actionName)) {
|
||||
case $this->getAction():
|
||||
return $this->handleAdd($gridField);
|
||||
@ -212,7 +227,8 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
||||
* @param GridField $grid
|
||||
* @return null
|
||||
*/
|
||||
public function handleAdd($grid) {
|
||||
public function handleAdd($grid)
|
||||
{
|
||||
$classes = $this->getClassesCreate($grid);
|
||||
if (empty($classes)) {
|
||||
throw new SS_HTTPResponse_Exception(400);
|
||||
|
@ -3,14 +3,15 @@
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
class UserForm extends Form {
|
||||
class UserForm extends Form
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Controller $controller
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(Controller $controller, $name = 'Form') {
|
||||
|
||||
public function __construct(Controller $controller, $name = 'Form')
|
||||
{
|
||||
$this->controller = $controller;
|
||||
$this->setRedirectToFormOnValidationError(true);
|
||||
|
||||
@ -64,14 +65,16 @@ class UserForm extends Form {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastEdited() {
|
||||
public function getLastEdited()
|
||||
{
|
||||
return $this->controller->LastEdited;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getDisplayErrorMessagesAtTop() {
|
||||
public function getDisplayErrorMessagesAtTop()
|
||||
{
|
||||
return (bool)$this->controller->DisplayErrorMessagesAtTop;
|
||||
}
|
||||
|
||||
@ -80,7 +83,8 @@ class UserForm extends Form {
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function getSteps() {
|
||||
public function getSteps()
|
||||
{
|
||||
return $this->Fields()->filterByCallback(function ($field) {
|
||||
return $field instanceof UserFormsStepField;
|
||||
});
|
||||
@ -95,7 +99,8 @@ class UserForm extends Form {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFormFields() {
|
||||
public function getFormFields()
|
||||
{
|
||||
$fields = new UserFormsFieldList();
|
||||
$target = $fields;
|
||||
foreach ($this->controller->Fields() as $field) {
|
||||
@ -116,7 +121,8 @@ class UserForm extends Form {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFormActions() {
|
||||
public function getFormActions()
|
||||
{
|
||||
$submitText = ($this->controller->SubmitButtonText) ? $this->controller->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
|
||||
$clearText = ($this->controller->ClearButtonText) ? $this->controller->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
|
||||
|
||||
@ -138,7 +144,8 @@ class UserForm extends Form {
|
||||
*
|
||||
* @return RequiredFields
|
||||
*/
|
||||
public function getRequiredFields() {
|
||||
public function getRequiredFields()
|
||||
{
|
||||
// Generate required field validator
|
||||
$requiredNames = $this
|
||||
->getController()
|
||||
@ -156,7 +163,8 @@ class UserForm extends Form {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes() {
|
||||
public function getAttributes()
|
||||
{
|
||||
$attrs = parent::getAttributes();
|
||||
|
||||
$attrs['class'] = $attrs['class'] . ' userform';
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @method EditableFormField Parent()
|
||||
* @package userforms
|
||||
*/
|
||||
class EditableCustomRule extends DataObject {
|
||||
class EditableCustomRule extends DataObject
|
||||
{
|
||||
|
||||
private static $condition_options = array(
|
||||
"IsBlank" => "Is blank",
|
||||
@ -46,7 +47,8 @@ class EditableCustomRule extends DataObject {
|
||||
*
|
||||
* Wrapper for the {@link Versioned} publish function
|
||||
*/
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false)
|
||||
{
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
@ -55,7 +57,8 @@ class EditableCustomRule extends DataObject {
|
||||
*
|
||||
* Wrapper for the {@link Versioned} deleteFromStage function
|
||||
*/
|
||||
public function doDeleteFromStage($stage) {
|
||||
public function doDeleteFromStage($stage)
|
||||
{
|
||||
$this->deleteFromStage($stage);
|
||||
}
|
||||
|
||||
@ -64,7 +67,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
@ -72,7 +76,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return $this->Parent()->canEdit($member);
|
||||
}
|
||||
|
||||
@ -80,7 +85,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
return $this->Parent()->canView($member);
|
||||
}
|
||||
|
||||
@ -91,7 +97,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param array $context Virtual parameter to allow context to be passed in to check
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
// Check parent page
|
||||
$parent = $this->getCanCreateContext(func_get_args());
|
||||
if ($parent) {
|
||||
@ -108,7 +115,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param array $args List of arguments passed to canCreate
|
||||
* @return DataObject Some parent dataobject to inherit permissions from
|
||||
*/
|
||||
protected function getCanCreateContext($args) {
|
||||
protected function getCanCreateContext($args)
|
||||
{
|
||||
// Inspect second parameter to canCreate for a 'Parent' context
|
||||
if (isset($args[1]['Parent'])) {
|
||||
return $args[1]['Parent'];
|
||||
@ -126,7 +134,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canPublish($member = null) {
|
||||
public function canPublish($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
@ -134,7 +143,8 @@ class EditableCustomRule extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canUnpublish($member = null) {
|
||||
public function canUnpublish($member = null)
|
||||
{
|
||||
return $this->canDelete($member);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserDefinedForm extends Page {
|
||||
class UserDefinedForm extends Page
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -117,7 +118,8 @@ class UserDefinedForm extends Page {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
|
||||
|
||||
$self = $this;
|
||||
@ -253,7 +255,8 @@ SQL;
|
||||
*
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function FilteredEmailRecipients($data = null, $form = null) {
|
||||
public function FilteredEmailRecipients($data = null, $form = null)
|
||||
{
|
||||
$recipients = new ArrayList($this->EmailRecipients()->toArray());
|
||||
|
||||
// Filter by rules
|
||||
@ -272,7 +275,8 @@ SQL;
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFormOptions() {
|
||||
public function getFormOptions()
|
||||
{
|
||||
$submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
|
||||
$clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
|
||||
|
||||
@ -297,11 +301,13 @@ SQL;
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorContainerID() {
|
||||
public function getErrorContainerID()
|
||||
{
|
||||
return $this->config()->error_container_id;
|
||||
}
|
||||
|
||||
public function requireDefaultRecords() {
|
||||
public function requireDefaultRecords()
|
||||
{
|
||||
parent::requireDefaultRecords();
|
||||
|
||||
if (!$this->config()->upgrade_on_build) {
|
||||
@ -321,7 +327,8 @@ SQL;
|
||||
/**
|
||||
* Validate formfields
|
||||
*/
|
||||
public function getCMSValidator() {
|
||||
public function getCMSValidator()
|
||||
{
|
||||
return new UserFormValidator();
|
||||
}
|
||||
}
|
||||
@ -332,7 +339,8 @@ SQL;
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserDefinedForm_Controller extends Page_Controller {
|
||||
class UserDefinedForm_Controller extends Page_Controller
|
||||
{
|
||||
|
||||
private static $finished_anchor = '#uff';
|
||||
|
||||
@ -343,7 +351,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
'finished'
|
||||
);
|
||||
|
||||
public function init() {
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// load the jquery
|
||||
@ -378,7 +387,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index() {
|
||||
public function index()
|
||||
{
|
||||
if ($this->Content && $form = $this->Form()) {
|
||||
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
||||
if ($hasLocation) {
|
||||
@ -401,7 +411,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function ping() {
|
||||
public function ping()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -411,7 +422,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
*
|
||||
* @return Forms
|
||||
*/
|
||||
public function Form() {
|
||||
public function Form()
|
||||
{
|
||||
$form = UserForm::create($this);
|
||||
$this->generateConditionalJavascript();
|
||||
return $form;
|
||||
@ -422,7 +434,8 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function generateConditionalJavascript() {
|
||||
public function generateConditionalJavascript()
|
||||
{
|
||||
$default = "";
|
||||
$rules = "";
|
||||
|
||||
@ -617,7 +630,8 @@ JS
|
||||
*
|
||||
* @return Redirection
|
||||
*/
|
||||
public function process($data, $form) {
|
||||
public function process($data, $form)
|
||||
{
|
||||
$submittedForm = Object::create('SubmittedForm');
|
||||
$submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
|
||||
$submittedForm->ParentID = $this->ID;
|
||||
@ -696,7 +710,6 @@ JS
|
||||
|
||||
// email users on submit.
|
||||
if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
$email = new UserFormRecipientEmail($submittedFields);
|
||||
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
|
||||
@ -768,8 +781,7 @@ JS
|
||||
|
||||
$email->setBody($body);
|
||||
$email->sendPlain();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$email->send();
|
||||
}
|
||||
}
|
||||
@ -812,7 +824,8 @@ JS
|
||||
* @param ArrayList fields
|
||||
* @return ArrayData
|
||||
*/
|
||||
private function getMergeFieldsMap($fields = array()) {
|
||||
private function getMergeFieldsMap($fields = array())
|
||||
{
|
||||
$data = new ArrayData(array());
|
||||
|
||||
foreach ($fields as $field) {
|
||||
@ -828,7 +841,8 @@ JS
|
||||
*
|
||||
* @return ViewableData
|
||||
*/
|
||||
public function finished() {
|
||||
public function finished()
|
||||
{
|
||||
$submission = Session::get('userformssubmission'. $this->ID);
|
||||
|
||||
if ($submission) {
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableCheckbox extends EditableFormField {
|
||||
class EditableCheckbox extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Checkbox Field';
|
||||
|
||||
@ -20,7 +21,8 @@ class EditableCheckbox extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->replaceField('Default', CheckboxField::create(
|
||||
@ -31,7 +33,8 @@ class EditableCheckbox extends EditableFormField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault)
|
||||
->setFieldHolderTemplate('UserFormsCheckboxField_holder')
|
||||
->setTemplate('UserFormsCheckboxField');
|
||||
@ -41,13 +44,15 @@ class EditableCheckbox extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getValueFromData($data) {
|
||||
public function getValueFromData($data)
|
||||
{
|
||||
$value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
||||
|
||||
return ($value) ? _t('EditableFormField.YES', 'Yes') : _t('EditableFormField.NO', 'No');
|
||||
}
|
||||
|
||||
public function migrateSettings($data) {
|
||||
public function migrateSettings($data)
|
||||
{
|
||||
// Migrate 'Default' setting to 'CheckedDefault'
|
||||
if (isset($data['Default'])) {
|
||||
$this->CheckedDefault = (bool)$data['Default'];
|
||||
|
@ -7,13 +7,15 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
||||
class EditableCheckboxGroupField extends EditableMultipleOptionField
|
||||
{
|
||||
|
||||
private static $singular_name = "Checkbox Group";
|
||||
|
||||
private static $plural_name = "Checkbox Groups";
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
||||
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
||||
|
||||
@ -27,7 +29,8 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getValueFromData($data) {
|
||||
public function getValueFromData($data)
|
||||
{
|
||||
$result = '';
|
||||
$entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
||||
|
||||
@ -46,7 +49,8 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
||||
{
|
||||
// watch out for checkboxs as the inputs don't have values but are 'checked
|
||||
// @todo - Test this
|
||||
if ($rule->FieldValue) {
|
||||
|
@ -5,7 +5,8 @@
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
class EditableCountryDropdownField extends EditableFormField {
|
||||
class EditableCountryDropdownField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Country Dropdown';
|
||||
|
||||
@ -14,7 +15,8 @@ class EditableCountryDropdownField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName('Default');
|
||||
@ -22,7 +24,8 @@ class EditableCountryDropdownField extends EditableFormField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = CountryDropdownField::create($this->Name, $this->EscapedTitle)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
->setTemplate('UserFormsDropdownField');
|
||||
@ -32,18 +35,21 @@ class EditableCountryDropdownField extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getValueFromData($data) {
|
||||
public function getValueFromData($data)
|
||||
{
|
||||
if (isset($data[$this->Name])) {
|
||||
$source = $this->getFormField()->getSource();
|
||||
return $source[$data[$this->Name]];
|
||||
}
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
public function getIcon()
|
||||
{
|
||||
return USERFORMS_DIR . '/images/editabledropdown.png';
|
||||
}
|
||||
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
||||
{
|
||||
return "$(\"select[name='{$this->Name}']\")";
|
||||
}
|
||||
}
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableDateField extends EditableFormField {
|
||||
class EditableDateField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Date Field';
|
||||
|
||||
@ -20,7 +21,8 @@ class EditableDateField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
@ -39,7 +41,8 @@ class EditableDateField extends EditableFormField {
|
||||
* Return the form field
|
||||
*
|
||||
*/
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$defaultValue = $this->DefaultToToday
|
||||
? SS_Datetime::now()->Format('Y-m-d')
|
||||
: $this->Default;
|
||||
@ -58,9 +61,11 @@ class EditableDateField extends EditableFormField {
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
class EditableDateField_FormField extends DateField {
|
||||
class EditableDateField_FormField extends DateField
|
||||
{
|
||||
|
||||
public function Type() {
|
||||
public function Type()
|
||||
{
|
||||
return "date-alt text";
|
||||
}
|
||||
}
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableDropdown extends EditableMultipleOptionField {
|
||||
class EditableDropdown extends EditableMultipleOptionField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Dropdown Field';
|
||||
|
||||
@ -16,7 +17,8 @@ class EditableDropdown extends EditableMultipleOptionField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName('Default');
|
||||
@ -27,7 +29,8 @@ class EditableDropdown extends EditableMultipleOptionField {
|
||||
/**
|
||||
* @return DropdownField
|
||||
*/
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap())
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
->setTemplate('UserFormsDropdownField');
|
||||
@ -41,7 +44,8 @@ class EditableDropdown extends EditableMultipleOptionField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
||||
{
|
||||
return "$(\"select[name='{$this->Name}']\")";
|
||||
}
|
||||
}
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableEmailField extends EditableFormField {
|
||||
class EditableEmailField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Email Field';
|
||||
|
||||
@ -17,7 +18,8 @@ class EditableEmailField extends EditableFormField {
|
||||
'Placeholder' => 'Varchar(255)'
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
@ -31,11 +33,13 @@ class EditableEmailField extends EditableFormField {
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
public function getSetsOwnError() {
|
||||
public function getSetsOwnError()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
->setTemplate('UserFormsField');
|
||||
@ -50,7 +54,8 @@ class EditableEmailField extends EditableFormField {
|
||||
*
|
||||
* @param FormField $field
|
||||
*/
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
parent::updateFormField($field);
|
||||
|
||||
$field->setAttribute('data-rule-email', true);
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Specifies that this ends a group of fields
|
||||
*/
|
||||
class EditableFieldGroup extends EditableFormField {
|
||||
class EditableFieldGroup extends EditableFormField
|
||||
{
|
||||
|
||||
private static $has_one = array(
|
||||
'End' => 'EditableFieldGroupEnd'
|
||||
@ -24,13 +25,15 @@ class EditableFieldGroup extends EditableFormField {
|
||||
*/
|
||||
private static $literal = true;
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getCMSTitle() {
|
||||
public function getCMSTitle()
|
||||
{
|
||||
$title = $this->getFieldNumber()
|
||||
?: $this->Title
|
||||
?: 'group';
|
||||
@ -44,15 +47,18 @@ class EditableFieldGroup extends EditableFormField {
|
||||
);
|
||||
}
|
||||
|
||||
public function getInlineClassnameField($column, $fieldClasses) {
|
||||
public function getInlineClassnameField($column, $fieldClasses)
|
||||
{
|
||||
return new LabelField($column, $this->CMSTitle);
|
||||
}
|
||||
|
||||
public function showInReports() {
|
||||
public function showInReports()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = UserFormsGroupField::create()
|
||||
->setTitle($this->EscapedTitle ?: false)
|
||||
->setName($this->Name);
|
||||
@ -60,7 +66,8 @@ class EditableFieldGroup extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
// set the right title on this field
|
||||
if ($this->RightTitle) {
|
||||
// Since this field expects raw html, safely escape the user data prior
|
||||
@ -73,14 +80,16 @@ class EditableFieldGroup extends EditableFormField {
|
||||
}
|
||||
}
|
||||
|
||||
protected function onBeforeDelete() {
|
||||
protected function onBeforeDelete()
|
||||
{
|
||||
parent::onBeforeDelete();
|
||||
|
||||
// Ensures EndID is lazy-loaded for onAfterDelete
|
||||
$this->EndID;
|
||||
}
|
||||
|
||||
protected function onAfterDelete() {
|
||||
protected function onAfterDelete()
|
||||
{
|
||||
parent::onAfterDelete();
|
||||
|
||||
// Delete end
|
||||
@ -88,5 +97,4 @@ class EditableFieldGroup extends EditableFormField {
|
||||
$end->delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
/**
|
||||
* Specifies that this ends a group of fields
|
||||
*/
|
||||
class EditableFieldGroupEnd extends EditableFormField {
|
||||
class EditableFieldGroupEnd extends EditableFormField
|
||||
{
|
||||
|
||||
private static $belongs_to = array(
|
||||
'Group' => 'EditableFieldGroup'
|
||||
@ -25,7 +26,8 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
*/
|
||||
private static $literal = true;
|
||||
|
||||
public function getCMSTitle() {
|
||||
public function getCMSTitle()
|
||||
{
|
||||
$group = $this->Group();
|
||||
return _t(
|
||||
'EditableFieldGroupEnd.FIELD_GROUP_END',
|
||||
@ -36,29 +38,35 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
);
|
||||
}
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getInlineClassnameField($column, $fieldClasses) {
|
||||
public function getInlineClassnameField($column, $fieldClasses)
|
||||
{
|
||||
return new LabelField($column, $this->CMSTitle);
|
||||
}
|
||||
|
||||
public function getInlineTitleField($column) {
|
||||
public function getInlineTitleField($column)
|
||||
{
|
||||
return HiddenField::create($column);
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function showInReports() {
|
||||
public function showInReports()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onAfterWrite() {
|
||||
public function onAfterWrite()
|
||||
{
|
||||
parent::onAfterWrite();
|
||||
|
||||
// If this is not attached to a group, find the first group prior to this
|
||||
@ -82,7 +90,8 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
}
|
||||
}
|
||||
|
||||
protected function onAfterDelete() {
|
||||
protected function onAfterDelete()
|
||||
{
|
||||
parent::onAfterDelete();
|
||||
|
||||
// Delete group
|
||||
@ -90,5 +99,4 @@ class EditableFieldGroupEnd extends EditableFormField {
|
||||
$group->delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableFileField extends EditableFormField {
|
||||
class EditableFileField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'File Upload Field';
|
||||
|
||||
@ -28,7 +29,8 @@ class EditableFileField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->addFieldToTab(
|
||||
@ -48,7 +50,8 @@ class EditableFileField extends EditableFormField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = FileField::create($this->Name, $this->EscapedTitle)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
->setTemplate('UserFormsFileField');
|
||||
@ -83,16 +86,19 @@ class EditableFileField extends EditableFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueFromData() {
|
||||
public function getValueFromData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getSubmittedFormField() {
|
||||
public function getSubmittedFormField()
|
||||
{
|
||||
return new SubmittedFileField();
|
||||
}
|
||||
|
||||
|
||||
public function migrateSettings($data) {
|
||||
public function migrateSettings($data)
|
||||
{
|
||||
// Migrate 'Folder' setting to 'FolderID'
|
||||
if (isset($data['Folder'])) {
|
||||
$this->FolderID = $data['Folder'];
|
||||
|
@ -17,7 +17,8 @@ use SilverStripe\Forms\SegmentField;
|
||||
* @method UserDefinedForm Parent() Parent page
|
||||
* @method DataList DisplayRules() List of EditableCustomRule objects
|
||||
*/
|
||||
class EditableFormField extends DataObject {
|
||||
class EditableFormField extends DataObject
|
||||
{
|
||||
|
||||
/**
|
||||
* Set to true to hide from class selector
|
||||
@ -128,7 +129,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @param bool
|
||||
*/
|
||||
public function setReadonly($readonly = true) {
|
||||
public function setReadonly($readonly = true)
|
||||
{
|
||||
$this->readonly = $readonly;
|
||||
}
|
||||
|
||||
@ -137,14 +139,16 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isReadonly() {
|
||||
private function isReadonly()
|
||||
{
|
||||
return $this->readonly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = new FieldList(new TabSet('Root'));
|
||||
|
||||
// Main tab
|
||||
@ -233,7 +237,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
protected function getDisplayRuleFields() {
|
||||
protected function getDisplayRuleFields()
|
||||
{
|
||||
// Check display rules
|
||||
if ($this->Required) {
|
||||
return new FieldList(
|
||||
@ -301,14 +306,14 @@ class EditableFormField extends DataObject {
|
||||
);
|
||||
}
|
||||
|
||||
public function onBeforeWrite() {
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
parent::onBeforeWrite();
|
||||
|
||||
// Set a field name.
|
||||
if (!$this->Name) {
|
||||
// New random name
|
||||
$this->Name = $this->generateName();
|
||||
|
||||
} elseif ($this->Name === 'Field') {
|
||||
throw new ValidationException('Field name cannot be "Field"');
|
||||
}
|
||||
@ -326,7 +331,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateName() {
|
||||
protected function generateName()
|
||||
{
|
||||
do {
|
||||
// Generate a new random name after this class
|
||||
$class = get_class($this);
|
||||
@ -344,7 +350,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getSetsOwnError() {
|
||||
public function getSetsOwnError()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -355,7 +362,8 @@ class EditableFormField extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
@ -366,7 +374,8 @@ class EditableFormField extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
$parent = $this->Parent();
|
||||
if ($parent && $parent->exists()) {
|
||||
return $parent->canEdit($member) && !$this->isReadonly();
|
||||
@ -376,13 +385,11 @@ class EditableFormField extends DataObject {
|
||||
// 'Content Authors' and those with permission to edit the UDF page. (ie. CanEditType/EditorGroups)
|
||||
// This is to restore User Forms 2.x backwards compatibility.
|
||||
$controller = Controller::curr();
|
||||
if ($controller && $controller instanceof CMSPageEditController)
|
||||
{
|
||||
if ($controller && $controller instanceof CMSPageEditController) {
|
||||
$parent = $controller->getRecord($controller->currentPageID());
|
||||
// Only allow this behaviour on pages using UserFormFieldEditorExtension, such
|
||||
// as UserDefinedForm page type.
|
||||
if ($parent && $parent->hasExtension('UserFormFieldEditorExtension'))
|
||||
{
|
||||
if ($parent && $parent->hasExtension('UserFormFieldEditorExtension')) {
|
||||
return $parent->canEdit($member);
|
||||
}
|
||||
}
|
||||
@ -399,7 +406,8 @@ class EditableFormField extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
$parent = $this->Parent();
|
||||
if ($parent && $parent->exists()) {
|
||||
return $parent->canView($member);
|
||||
@ -415,7 +423,8 @@ class EditableFormField extends DataObject {
|
||||
* @param array $context Virtual parameter to allow context to be passed in to check
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
// Check parent page
|
||||
$parent = $this->getCanCreateContext(func_get_args());
|
||||
if ($parent) {
|
||||
@ -432,7 +441,8 @@ class EditableFormField extends DataObject {
|
||||
* @param array $args List of arguments passed to canCreate
|
||||
* @return SiteTree Parent page instance
|
||||
*/
|
||||
protected function getCanCreateContext($args) {
|
||||
protected function getCanCreateContext($args)
|
||||
{
|
||||
// Inspect second parameter to canCreate for a 'Parent' context
|
||||
if (isset($args[1]['Parent'])) {
|
||||
return $args[1]['Parent'];
|
||||
@ -452,7 +462,8 @@ class EditableFormField extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canPublish($member = null) {
|
||||
public function canPublish($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
@ -462,7 +473,8 @@ class EditableFormField extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canUnpublish($member = null) {
|
||||
public function canUnpublish($member = null)
|
||||
{
|
||||
return $this->canDelete($member);
|
||||
}
|
||||
|
||||
@ -471,7 +483,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* Wrapper for the {@link Versioned} publish function
|
||||
*/
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false)
|
||||
{
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
|
||||
// Don't forget to publish the related custom rules...
|
||||
@ -485,7 +498,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* Wrapper for the {@link Versioned} deleteFromStage function
|
||||
*/
|
||||
public function doDeleteFromStage($stage) {
|
||||
public function doDeleteFromStage($stage)
|
||||
{
|
||||
// Remove custom rules in this stage
|
||||
$rules = Versioned::get_by_stage('EditableCustomRule', $stage)
|
||||
->filter('ParentID', $this->ID);
|
||||
@ -500,10 +514,15 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* checks wether record is new, copied from Sitetree
|
||||
*/
|
||||
function isNew() {
|
||||
if(empty($this->ID)) return true;
|
||||
public function isNew()
|
||||
{
|
||||
if (empty($this->ID)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(is_numeric($this->ID)) return false;
|
||||
if (is_numeric($this->ID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stripos($this->ID, 'new') === 0;
|
||||
}
|
||||
@ -512,9 +531,12 @@ class EditableFormField extends DataObject {
|
||||
* checks if records is changed on stage
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsModifiedOnStage() {
|
||||
public function getIsModifiedOnStage()
|
||||
{
|
||||
// new unsaved fields could be never be published
|
||||
if($this->isNew()) return false;
|
||||
if ($this->isNew()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stageVersion = Versioned::get_versionnumber_by_stage('EditableFormField', 'Stage', $this->ID);
|
||||
$liveVersion = Versioned::get_versionnumber_by_stage('EditableFormField', 'Live', $this->ID);
|
||||
@ -525,7 +547,8 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* @deprecated since version 4.0
|
||||
*/
|
||||
public function getSettings() {
|
||||
public function getSettings()
|
||||
{
|
||||
Deprecation::notice('4.0', 'getSettings is deprecated');
|
||||
return (!empty($this->CustomSettings)) ? unserialize($this->CustomSettings) : array();
|
||||
}
|
||||
@ -533,7 +556,8 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* @deprecated since version 4.0
|
||||
*/
|
||||
public function setSettings($settings = array()) {
|
||||
public function setSettings($settings = array())
|
||||
{
|
||||
Deprecation::notice('4.0', 'setSettings is deprecated');
|
||||
$this->CustomSettings = serialize($settings);
|
||||
}
|
||||
@ -541,7 +565,8 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* @deprecated since version 4.0
|
||||
*/
|
||||
public function setSetting($key, $value) {
|
||||
public function setSetting($key, $value)
|
||||
{
|
||||
Deprecation::notice('4.0', "setSetting({$key}) is deprecated");
|
||||
$settings = $this->getSettings();
|
||||
$settings[$key] = $value;
|
||||
@ -554,7 +579,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @param array The permissible CSS classes to add
|
||||
*/
|
||||
public function setAllowedCss(array $allowed) {
|
||||
public function setAllowedCss(array $allowed)
|
||||
{
|
||||
if (is_array($allowed)) {
|
||||
foreach ($allowed as $k => $v) {
|
||||
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
|
||||
@ -565,7 +591,8 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* @deprecated since version 4.0
|
||||
*/
|
||||
public function getSetting($setting) {
|
||||
public function getSetting($setting)
|
||||
{
|
||||
Deprecation::notice("4.0", "getSetting({$setting}) is deprecated");
|
||||
|
||||
$settings = $this->getSettings();
|
||||
@ -582,7 +609,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIcon() {
|
||||
public function getIcon()
|
||||
{
|
||||
return USERFORMS_DIR . '/images/' . strtolower($this->class) . '.png';
|
||||
}
|
||||
|
||||
@ -592,7 +620,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getHasAddableOptions() {
|
||||
public function getHasAddableOptions()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -602,7 +631,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showExtraOptions() {
|
||||
public function showExtraOptions()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -611,7 +641,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEscapedTitle() {
|
||||
public function getEscapedTitle()
|
||||
{
|
||||
return Convert::raw2xml($this->Title);
|
||||
}
|
||||
|
||||
@ -623,7 +654,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFieldNumber() {
|
||||
public function getFieldNumber()
|
||||
{
|
||||
// Check if exists
|
||||
if (!$this->exists()) {
|
||||
return null;
|
||||
@ -654,14 +686,16 @@ class EditableFormField extends DataObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCMSTitle() {
|
||||
public function getCMSTitle()
|
||||
{
|
||||
return $this->i18n_singular_name() . ' (' . $this->Title . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since version 4.0
|
||||
*/
|
||||
public function getFieldName($field = false) {
|
||||
public function getFieldName($field = false)
|
||||
{
|
||||
Deprecation::notice('4.0', "getFieldName({$field}) is deprecated");
|
||||
return ($field) ? "Fields[".$this->ID."][".$field."]" : "Fields[".$this->ID."]";
|
||||
}
|
||||
@ -669,7 +703,8 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* @deprecated since version 4.0
|
||||
*/
|
||||
public function getSettingName($field) {
|
||||
public function getSettingName($field)
|
||||
{
|
||||
Deprecation::notice('4.0', "getSettingName({$field}) is deprecated");
|
||||
$name = $this->getFieldName('CustomSettings');
|
||||
|
||||
@ -682,7 +717,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFieldValidationOptions() {
|
||||
public function getFieldValidationOptions()
|
||||
{
|
||||
$fields = new FieldList(
|
||||
CheckboxField::create('Required', _t('EditableFormField.REQUIRED', 'Is this field Required?'))
|
||||
->setDescription(_t('EditableFormField.REQUIRED_DESCRIPTION', 'Please note that conditional fields can\'t be required')),
|
||||
@ -700,7 +736,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return FormField
|
||||
*/
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
user_error("Please implement a getFormField() on your EditableFormClass ". $this->ClassName, E_USER_ERROR);
|
||||
}
|
||||
|
||||
@ -709,7 +746,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @param FormField $field
|
||||
*/
|
||||
public function doUpdateFormField($field) {
|
||||
public function doUpdateFormField($field)
|
||||
{
|
||||
$this->extend('beforeUpdateFormField', $field);
|
||||
$this->updateFormField($field);
|
||||
$this->extend('afterUpdateFormField', $field);
|
||||
@ -720,7 +758,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @param FormField $field
|
||||
*/
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
// set the error / formatting messages
|
||||
$field->setCustomValidationMessage($this->getErrorMessage()->RAW());
|
||||
|
||||
@ -755,7 +794,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return SubmittedFormField
|
||||
*/
|
||||
public function getSubmittedFormField() {
|
||||
public function getSubmittedFormField()
|
||||
{
|
||||
return new SubmittedFormField();
|
||||
}
|
||||
|
||||
@ -765,7 +805,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showInReports() {
|
||||
public function showInReports()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -775,7 +816,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return Varchar
|
||||
*/
|
||||
public function getErrorMessage() {
|
||||
public function getErrorMessage()
|
||||
{
|
||||
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
|
||||
$standard = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title);
|
||||
|
||||
@ -791,7 +833,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @param array $data Unserialised data
|
||||
*/
|
||||
public function migrateSettings($data) {
|
||||
public function migrateSettings($data)
|
||||
{
|
||||
// Map 'Show' / 'Hide' to boolean
|
||||
if (isset($data['ShowOnLoad'])) {
|
||||
$this->ShowOnLoad = $data['ShowOnLoad'] === '' || ($data['ShowOnLoad'] && $data['ShowOnLoad'] !== 'Hide');
|
||||
@ -813,7 +856,8 @@ class EditableFormField extends DataObject {
|
||||
* @param array $fieldClasses List of allowed classnames if this formfield has a selectable class
|
||||
* @return FormField
|
||||
*/
|
||||
public function getInlineClassnameField($column, $fieldClasses) {
|
||||
public function getInlineClassnameField($column, $fieldClasses)
|
||||
{
|
||||
return DropdownField::create($column, false, $fieldClasses);
|
||||
}
|
||||
|
||||
@ -823,7 +867,8 @@ class EditableFormField extends DataObject {
|
||||
* @param string $column
|
||||
* @return FormField
|
||||
*/
|
||||
public function getInlineTitleField($column) {
|
||||
public function getInlineTitleField($column)
|
||||
{
|
||||
return TextField::create($column, false)
|
||||
->setAttribute('placeholder', _t('EditableFormField.TITLE', 'Title'))
|
||||
->setAttribute('data-placeholder', _t('EditableFormField.TITLE', 'Title'));
|
||||
@ -834,7 +879,8 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSelectorHolder() {
|
||||
public function getSelectorHolder()
|
||||
{
|
||||
return "$(\"#{$this->Name}\")";
|
||||
}
|
||||
|
||||
@ -844,7 +890,8 @@ class EditableFormField extends DataObject {
|
||||
* @param EditableCustomRule $rule Custom rule this selector will be used with
|
||||
* @param bool $forOnLoad Set to true if this will be invoked on load
|
||||
*/
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
||||
{
|
||||
return "$(\"input[name='{$this->Name}']\")";
|
||||
}
|
||||
|
||||
@ -855,7 +902,8 @@ class EditableFormField extends DataObject {
|
||||
* @param $includeLiterals Set to false to exclude non-data fields
|
||||
* @return array
|
||||
*/
|
||||
public function getEditableFieldClasses($includeLiterals = true) {
|
||||
public function getEditableFieldClasses($includeLiterals = true)
|
||||
{
|
||||
$classes = ClassInfo::getValidSubClasses('EditableFormField');
|
||||
|
||||
// Remove classes we don't want to display in the dropdown.
|
||||
@ -886,7 +934,8 @@ class EditableFormField extends DataObject {
|
||||
/**
|
||||
* @return EditableFormFieldValidator
|
||||
*/
|
||||
public function getCMSValidator() {
|
||||
public function getCMSValidator()
|
||||
{
|
||||
return EditableFormFieldValidator::create()
|
||||
->setRecord($this);
|
||||
}
|
||||
@ -896,11 +945,11 @@ class EditableFormField extends DataObject {
|
||||
*
|
||||
* @return SS_List
|
||||
*/
|
||||
public function EffectiveDisplayRules() {
|
||||
public function EffectiveDisplayRules()
|
||||
{
|
||||
if ($this->Required) {
|
||||
return new ArrayList();
|
||||
}
|
||||
return $this->DisplayRules();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class EditableFormFieldValidator extends RequiredFields {
|
||||
class EditableFormFieldValidator extends RequiredFields
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
@ -13,7 +14,8 @@ class EditableFormFieldValidator extends RequiredFields {
|
||||
* @param EditableFormField $record
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecord($record) {
|
||||
public function setRecord($record)
|
||||
{
|
||||
$this->record = $record;
|
||||
return $this;
|
||||
}
|
||||
@ -21,12 +23,14 @@ class EditableFormFieldValidator extends RequiredFields {
|
||||
/*
|
||||
* @return EditableFormField
|
||||
*/
|
||||
public function getRecord() {
|
||||
public function getRecord()
|
||||
{
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
|
||||
public function php($data) {
|
||||
public function php($data)
|
||||
{
|
||||
if (!parent::php($data)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableFormHeading extends EditableFormField {
|
||||
class EditableFormHeading extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Heading';
|
||||
|
||||
@ -26,7 +27,8 @@ class EditableFormHeading extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName(array('Default', 'Validation', 'RightTitle'));
|
||||
@ -55,7 +57,8 @@ class EditableFormHeading extends EditableFormField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$labelField = new HeaderField($this->Name, $this->EscapedTitle, $this->Level);
|
||||
$labelField->addExtraClass('FormHeading');
|
||||
$labelField->setAttribute('data-id', $this->Name);
|
||||
@ -63,7 +66,8 @@ class EditableFormHeading extends EditableFormField {
|
||||
return $labelField;
|
||||
}
|
||||
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
// set the right title on this field
|
||||
if ($this->RightTitle) {
|
||||
// Since this field expects raw html, safely escape the user data prior
|
||||
@ -75,19 +79,23 @@ class EditableFormHeading extends EditableFormField {
|
||||
}
|
||||
}
|
||||
|
||||
public function showInReports() {
|
||||
public function showInReports()
|
||||
{
|
||||
return !$this->HideFromReports;
|
||||
}
|
||||
|
||||
public function getFieldValidationOptions() {
|
||||
public function getFieldValidationOptions()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSelectorHolder() {
|
||||
public function getSelectorHolder()
|
||||
{
|
||||
return "$(\":header[data-id='{$this->Name}']\")";
|
||||
}
|
||||
|
||||
public function getLevel() {
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->getField('Level') ?: 3;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
class EditableFormStep extends EditableFormField {
|
||||
class EditableFormStep extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Page Break';
|
||||
|
||||
@ -21,7 +22,8 @@ class EditableFormStep extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName(array('MergeField', 'Default', 'Validation', 'RightTitle'));
|
||||
@ -32,7 +34,8 @@ class EditableFormStep extends EditableFormField {
|
||||
/**
|
||||
* @return FormField
|
||||
*/
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = UserFormsStepField::create()
|
||||
->setName($this->Name)
|
||||
->setTitle($this->EscapedTitle);
|
||||
@ -40,7 +43,8 @@ class EditableFormStep extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
// if this field has an extra class
|
||||
if ($this->ExtraClass) {
|
||||
$field->addExtraClass($this->ExtraClass);
|
||||
@ -50,18 +54,21 @@ class EditableFormStep extends EditableFormField {
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function showInReports() {
|
||||
public function showInReports()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getInlineClassnameField($column, $fieldClasses) {
|
||||
public function getInlineClassnameField($column, $fieldClasses)
|
||||
{
|
||||
return new LabelField(
|
||||
$column,
|
||||
$this->CMSTitle
|
||||
);
|
||||
}
|
||||
|
||||
public function getCMSTitle() {
|
||||
public function getCMSTitle()
|
||||
{
|
||||
$title = $this->getFieldNumber()
|
||||
?: $this->Title
|
||||
?: '';
|
||||
@ -80,7 +87,8 @@ class EditableFormStep extends EditableFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSelectorHolder() {
|
||||
public function getSelectorHolder()
|
||||
{
|
||||
return "$(\".step-button-wrapper[data-for='{$this->Name}']\")";
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableLiteralField extends EditableFormField {
|
||||
class EditableLiteralField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'HTML Block';
|
||||
|
||||
@ -44,9 +45,12 @@ class EditableLiteralField extends EditableFormField {
|
||||
*
|
||||
* @return HtmlEditorConfig
|
||||
*/
|
||||
protected function getEditorConfig() {
|
||||
protected function getEditorConfig()
|
||||
{
|
||||
$editorConfig = $this->config()->editor_config;
|
||||
if($editorConfig) return HtmlEditorConfig::get($editorConfig);
|
||||
if ($editorConfig) {
|
||||
return HtmlEditorConfig::get($editorConfig);
|
||||
}
|
||||
return HtmlEditorConfig::get_active();
|
||||
}
|
||||
|
||||
@ -56,9 +60,12 @@ class EditableLiteralField extends EditableFormField {
|
||||
* @param string $content Raw html
|
||||
* @return string Safely sanitised html
|
||||
*/
|
||||
protected function sanitiseContent($content) {
|
||||
protected function sanitiseContent($content)
|
||||
{
|
||||
// Check if sanitisation is enabled
|
||||
if(!HtmlEditorField::config()->sanitise_server_side) return $content;
|
||||
if (!HtmlEditorField::config()->sanitise_server_side) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
// Perform sanitisation
|
||||
$htmlValue = Injector::inst()->create('HTMLValue', $content);
|
||||
@ -72,7 +79,8 @@ class EditableLiteralField extends EditableFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent() {
|
||||
public function getContent()
|
||||
{
|
||||
// Apply html editor sanitisation rules
|
||||
$content = $this->getField('Content');
|
||||
return $this->sanitiseContent($content);
|
||||
@ -83,7 +91,8 @@ class EditableLiteralField extends EditableFormField {
|
||||
*
|
||||
* @param string $content
|
||||
*/
|
||||
public function setContent($content) {
|
||||
public function setContent($content)
|
||||
{
|
||||
// Apply html editor sanitisation rules
|
||||
$content = $this->sanitiseContent($content);
|
||||
$this->setField('Content', $content);
|
||||
@ -92,7 +101,8 @@ class EditableLiteralField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName(array('Default', 'Validation', 'RightTitle'));
|
||||
@ -114,7 +124,8 @@ class EditableLiteralField extends EditableFormField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
// Build label and css classes
|
||||
$label = '';
|
||||
$classes = $this->ExtraClass;
|
||||
@ -142,7 +153,8 @@ class EditableLiteralField extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function showInReports() {
|
||||
public function showInReports()
|
||||
{
|
||||
return ! $this->HideFromReports;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableMemberListField extends EditableFormField {
|
||||
class EditableMemberListField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Member List Field';
|
||||
|
||||
@ -18,7 +19,8 @@ class EditableMemberListField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName('Default');
|
||||
@ -36,7 +38,8 @@ class EditableMemberListField extends EditableFormField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
if (empty($this->GroupID)) {
|
||||
return false;
|
||||
}
|
||||
@ -47,7 +50,8 @@ class EditableMemberListField extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getValueFromData($data) {
|
||||
public function getValueFromData($data)
|
||||
{
|
||||
if (isset($data[$this->Name])) {
|
||||
$memberID = $data[$this->Name];
|
||||
$member = Member::get()->byID($memberID);
|
||||
|
@ -13,7 +13,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableMultipleOptionField extends EditableFormField {
|
||||
class EditableMultipleOptionField extends EditableFormField
|
||||
{
|
||||
|
||||
/**
|
||||
* Define this field as abstract (not inherited)
|
||||
@ -30,7 +31,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$editableColumns = new GridFieldEditableColumns();
|
||||
@ -87,7 +89,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false)
|
||||
{
|
||||
$live = Versioned::get_by_stage("EditableOption", "Live", "\"EditableOption\".\"ParentID\" = $this->ID");
|
||||
|
||||
if ($live) {
|
||||
@ -112,7 +115,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doDeleteFromStage($stage) {
|
||||
public function doDeleteFromStage($stage)
|
||||
{
|
||||
// Remove options
|
||||
$options = Versioned::get_by_stage('EditableOption', $stage)
|
||||
->filter('ParentID', $this->ID);
|
||||
@ -129,7 +133,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete() {
|
||||
public function delete()
|
||||
{
|
||||
$options = $this->Options();
|
||||
|
||||
if ($options) {
|
||||
@ -147,7 +152,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return DataObject
|
||||
*/
|
||||
public function duplicate($doWrite = true) {
|
||||
public function duplicate($doWrite = true)
|
||||
{
|
||||
$clonedNode = parent::duplicate();
|
||||
|
||||
foreach ($this->Options() as $field) {
|
||||
@ -166,7 +172,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getHasAddableOptions() {
|
||||
public function getHasAddableOptions()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -175,7 +182,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptionsMap() {
|
||||
protected function getOptionsMap()
|
||||
{
|
||||
$optionSet = $this->Options();
|
||||
$optionMap = $optionSet->map('Value', 'Title');
|
||||
if ($optionMap instanceof SS_Map) {
|
||||
@ -189,7 +197,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return SS_List
|
||||
*/
|
||||
protected function getDefaultOptions() {
|
||||
protected function getDefaultOptions()
|
||||
{
|
||||
return $this->Options()->filter('Default', 1);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableNumericField extends EditableFormField {
|
||||
class EditableNumericField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Numeric Field';
|
||||
|
||||
@ -19,11 +20,13 @@ class EditableNumericField extends EditableFormField {
|
||||
'Placeholder' => 'Varchar(255)'
|
||||
);
|
||||
|
||||
public function getSetsOwnError() {
|
||||
public function getSetsOwnError()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
@ -40,7 +43,8 @@ class EditableNumericField extends EditableFormField {
|
||||
/**
|
||||
* @return NumericField
|
||||
*/
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = NumericField::create($this->Name, $this->EscapedTitle, $this->Default)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
->setTemplate('UserFormsField')
|
||||
@ -51,7 +55,8 @@ class EditableNumericField extends EditableFormField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getFieldValidationOptions() {
|
||||
public function getFieldValidationOptions()
|
||||
{
|
||||
$fields = parent::getFieldValidationOptions();
|
||||
$fields->push(FieldGroup::create(
|
||||
_t("EditableNumericField.RANGE", "Allowed numeric range"),
|
||||
@ -69,7 +74,8 @@ class EditableNumericField extends EditableFormField {
|
||||
*
|
||||
* @param FormField $field
|
||||
*/
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
parent::updateFormField($field);
|
||||
|
||||
if ($this->MinValue) {
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @method EditableMultipleOptionField Parent()
|
||||
* @package userforms
|
||||
*/
|
||||
class EditableOption extends DataObject {
|
||||
class EditableOption extends DataObject
|
||||
{
|
||||
|
||||
private static $default_sort = "Sort";
|
||||
|
||||
@ -39,7 +40,8 @@ class EditableOption extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function allow_empty_values() {
|
||||
public static function allow_empty_values()
|
||||
{
|
||||
return (bool) self::$allow_empty_values;
|
||||
}
|
||||
|
||||
@ -48,7 +50,8 @@ class EditableOption extends DataObject {
|
||||
*
|
||||
* @param boolean $allow
|
||||
*/
|
||||
public static function set_allow_empty_values($allow) {
|
||||
public static function set_allow_empty_values($allow)
|
||||
{
|
||||
self::$allow_empty_values = (bool) $allow;
|
||||
}
|
||||
|
||||
@ -57,7 +60,8 @@ class EditableOption extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return $this->Parent()->canEdit($member);
|
||||
}
|
||||
|
||||
@ -66,11 +70,13 @@ class EditableOption extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
public function getEscapedTitle() {
|
||||
public function getEscapedTitle()
|
||||
{
|
||||
return Convert::raw2att($this->Title);
|
||||
}
|
||||
|
||||
@ -78,7 +84,8 @@ class EditableOption extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
return $this->Parent()->canView($member);
|
||||
}
|
||||
|
||||
@ -89,7 +96,8 @@ class EditableOption extends DataObject {
|
||||
* @param array $context Virtual parameter to allow context to be passed in to check
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
// Check parent page
|
||||
$parent = $this->getCanCreateContext(func_get_args());
|
||||
if ($parent) {
|
||||
@ -106,7 +114,8 @@ class EditableOption extends DataObject {
|
||||
* @param array $args List of arguments passed to canCreate
|
||||
* @return DataObject Some parent dataobject to inherit permissions from
|
||||
*/
|
||||
protected function getCanCreateContext($args) {
|
||||
protected function getCanCreateContext($args)
|
||||
{
|
||||
// Inspect second parameter to canCreate for a 'Parent' context
|
||||
if (isset($args[1]['Parent'])) {
|
||||
return $args[1]['Parent'];
|
||||
@ -124,7 +133,8 @@ class EditableOption extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canPublish($member = null) {
|
||||
public function canPublish($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
@ -132,7 +142,8 @@ class EditableOption extends DataObject {
|
||||
* @param Member $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canUnpublish($member = null) {
|
||||
public function canUnpublish($member = null)
|
||||
{
|
||||
return $this->canDelete($member);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableRadioField extends EditableMultipleOptionField {
|
||||
class EditableRadioField extends EditableMultipleOptionField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Radio Group';
|
||||
|
||||
@ -16,7 +17,8 @@ class EditableRadioField extends EditableMultipleOptionField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->removeByName('Default');
|
||||
@ -24,7 +26,8 @@ class EditableRadioField extends EditableMultipleOptionField {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
$field = OptionsetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
||||
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
|
||||
|
||||
@ -37,7 +40,8 @@ class EditableRadioField extends EditableMultipleOptionField {
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
||||
{
|
||||
// We only want to trigger on load once for the radio group - hence we focus on the first option only.
|
||||
$first = $forOnLoad ? ':first' : '';
|
||||
return "$(\"input[name='{$this->Name}']{$first}\")";
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableTextField extends EditableFormField {
|
||||
class EditableTextField extends EditableFormField
|
||||
{
|
||||
|
||||
private static $singular_name = 'Text Field';
|
||||
|
||||
@ -24,7 +25,8 @@ class EditableTextField extends EditableFormField {
|
||||
'Rows' => 1
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$this->beforeUpdateCMSFields(function ($fields) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
@ -52,7 +54,8 @@ class EditableTextField extends EditableFormField {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getFieldValidationOptions() {
|
||||
public function getFieldValidationOptions()
|
||||
{
|
||||
$fields = parent::getFieldValidationOptions();
|
||||
|
||||
$fields->merge(array(
|
||||
@ -72,7 +75,8 @@ class EditableTextField extends EditableFormField {
|
||||
/**
|
||||
* @return TextareaField|TextField
|
||||
*/
|
||||
public function getFormField() {
|
||||
public function getFormField()
|
||||
{
|
||||
if ($this->Rows > 1) {
|
||||
$field = TextareaField::create($this->Name, $this->EscapedTitle, $this->Default)
|
||||
->setFieldHolderTemplate('UserFormsField_holder')
|
||||
@ -94,7 +98,8 @@ class EditableTextField extends EditableFormField {
|
||||
*
|
||||
* @param FormField $field
|
||||
*/
|
||||
protected function updateFormField($field) {
|
||||
protected function updateFormField($field)
|
||||
{
|
||||
parent::updateFormField($field);
|
||||
|
||||
if (is_numeric($this->MinLength) && $this->MinLength > 0) {
|
||||
|
@ -7,7 +7,8 @@
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
class UserDefinedForm_EmailRecipient extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'EmailAddress' => 'Varchar(200)',
|
||||
@ -50,7 +51,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*/
|
||||
private static $allow_unbound_recipient_fields = false;
|
||||
|
||||
public function summaryFields() {
|
||||
public function summaryFields()
|
||||
{
|
||||
$fields = parent::summaryFields();
|
||||
if (isset($fields['EmailAddress'])) {
|
||||
$fields['EmailAddress'] = _t('UserDefinedForm.EMAILADDRESS', 'Email');
|
||||
@ -69,14 +71,16 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return UserDefinedFrom
|
||||
*/
|
||||
protected function getFormParent() {
|
||||
protected function getFormParent()
|
||||
{
|
||||
$formID = $this->FormID
|
||||
? $this->FormID
|
||||
: Session::get('CMSMain.currentPage');
|
||||
return UserDefinedForm::get()->byID($formID);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
public function getTitle()
|
||||
{
|
||||
if ($this->EmailAddress) {
|
||||
return $this->EmailAddress;
|
||||
}
|
||||
@ -91,7 +95,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return GridFieldConfig
|
||||
*/
|
||||
protected function getRulesConfig() {
|
||||
protected function getRulesConfig()
|
||||
{
|
||||
$formFields = $this->getFormParent()->Fields();
|
||||
|
||||
$config = GridFieldConfig::create()
|
||||
@ -122,7 +127,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
Requirements::javascript(USERFORMS_DIR . '/javascript/Recipient.js');
|
||||
|
||||
// Determine optional field values
|
||||
@ -296,7 +302,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
* @param array $context Virtual parameter to allow context to be passed in to check
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
// Check parent page
|
||||
$parent = $this->getCanCreateContext(func_get_args());
|
||||
if ($parent) {
|
||||
@ -313,7 +320,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
* @param array $args List of arguments passed to canCreate
|
||||
* @return SiteTree Parent page instance
|
||||
*/
|
||||
protected function getCanCreateContext($args) {
|
||||
protected function getCanCreateContext($args)
|
||||
{
|
||||
// Inspect second parameter to canCreate for a 'Parent' context
|
||||
if (isset($args[1]['Form'])) {
|
||||
return $args[1]['Form'];
|
||||
@ -332,7 +340,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
return $this->Form()->canView($member);
|
||||
}
|
||||
|
||||
@ -341,7 +350,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return $this->Form()->canEdit($member);
|
||||
}
|
||||
|
||||
@ -350,7 +360,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
@ -361,7 +372,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
* @param Form $form
|
||||
* @return bool
|
||||
*/
|
||||
public function canSend($data, $form) {
|
||||
public function canSend($data, $form)
|
||||
{
|
||||
// Skip if no rules configured
|
||||
$customRules = $this->CustomRules();
|
||||
if (!$customRules->count()) {
|
||||
@ -391,7 +403,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function emailTemplateExists($template = '') {
|
||||
public function emailTemplateExists($template = '')
|
||||
{
|
||||
$t = ($template ? $template : $this->EmailTemplate);
|
||||
|
||||
return in_array($t, $this->getEmailTemplateDropdownValues());
|
||||
@ -402,7 +415,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmailBodyContent() {
|
||||
public function getEmailBodyContent()
|
||||
{
|
||||
return $this->SendPlain ? $this->EmailBody : $this->EmailBodyHtml;
|
||||
}
|
||||
|
||||
@ -411,7 +425,8 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEmailTemplateDropdownValues() {
|
||||
public function getEmailTemplateDropdownValues()
|
||||
{
|
||||
$templates = array();
|
||||
|
||||
$finder = new SS_FileFinder();
|
||||
|
@ -6,7 +6,8 @@
|
||||
*
|
||||
* @method UserDefinedForm_EmailRecipient Parent()
|
||||
*/
|
||||
class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
class UserDefinedForm_EmailRecipientCondition extends DataObject
|
||||
{
|
||||
|
||||
/**
|
||||
* List of options
|
||||
@ -38,7 +39,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
* @param Form $form
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($data, $form) {
|
||||
public function matches($data, $form)
|
||||
{
|
||||
$fieldName = $this->ConditionField()->Name;
|
||||
$fieldValue = isset($data[$fieldName]) ? $data[$fieldName] : null;
|
||||
switch ($this->ConditionOption) {
|
||||
@ -61,7 +63,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
* @param array $context Virtual parameter to allow context to be passed in to check
|
||||
* @return bool
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
// Check parent page
|
||||
$parent = $this->getCanCreateContext(func_get_args());
|
||||
if ($parent) {
|
||||
@ -78,7 +81,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
* @param array $args List of arguments passed to canCreate
|
||||
* @return SiteTree Parent page instance
|
||||
*/
|
||||
protected function getCanCreateContext($args) {
|
||||
protected function getCanCreateContext($args)
|
||||
{
|
||||
// Inspect second parameter to canCreate for a 'Parent' context
|
||||
if (isset($args[1]['Parent'])) {
|
||||
return $args[1]['Parent'];
|
||||
@ -97,7 +101,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
return $this->Parent()->canView($member);
|
||||
}
|
||||
|
||||
@ -106,7 +111,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return $this->Parent()->canEdit($member);
|
||||
}
|
||||
|
||||
@ -115,7 +121,8 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,15 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserFormRecipientEmail extends Email {
|
||||
class UserFormRecipientEmail extends Email
|
||||
{
|
||||
|
||||
protected $ss_template = "SubmittedFormEmail";
|
||||
|
||||
protected $data;
|
||||
|
||||
public function __construct($submittedFields = null) {
|
||||
public function __construct($submittedFields = null)
|
||||
{
|
||||
parent::__construct($submittedFields = null);
|
||||
}
|
||||
|
||||
@ -24,7 +26,8 @@ class UserFormRecipientEmail extends Email {
|
||||
*
|
||||
* @param string $email The email address to set the "Reply-To" header to
|
||||
*/
|
||||
public function setReplyTo($email) {
|
||||
public function setReplyTo($email)
|
||||
{
|
||||
$this->customHeaders['Reply-To'] = $email;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest {
|
||||
class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
|
||||
{
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'edit',
|
||||
@ -17,7 +18,8 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest {
|
||||
/**
|
||||
* Renders a preview of the recipient email.
|
||||
*/
|
||||
public function preview() {
|
||||
public function preview()
|
||||
{
|
||||
return $this->customise(new ArrayData(array(
|
||||
'Body' => $this->record->getEmailBodyContent(),
|
||||
'HideFormData' => $this->record->HideFormData,
|
||||
@ -29,7 +31,8 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest {
|
||||
* Get some placeholder field values to display in the preview
|
||||
* @return ArrayList
|
||||
*/
|
||||
private function getPreviewFieldData() {
|
||||
private function getPreviewFieldData()
|
||||
{
|
||||
$data = new ArrayList();
|
||||
|
||||
$fields = $this->record->Form()->Fields()->filter(array(
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class SubmittedFileField extends SubmittedFormField {
|
||||
class SubmittedFileField extends SubmittedFormField
|
||||
{
|
||||
|
||||
private static $has_one = array(
|
||||
"UploadedFile" => "File"
|
||||
@ -19,7 +20,8 @@ class SubmittedFileField extends SubmittedFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedValue() {
|
||||
public function getFormattedValue()
|
||||
{
|
||||
$name = $this->getFileName();
|
||||
$link = $this->getLink();
|
||||
$title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
|
||||
@ -39,7 +41,8 @@ class SubmittedFileField extends SubmittedFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExportValue() {
|
||||
public function getExportValue()
|
||||
{
|
||||
return ($link = $this->getLink()) ? $link : "";
|
||||
}
|
||||
|
||||
@ -48,7 +51,8 @@ class SubmittedFileField extends SubmittedFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLink() {
|
||||
public function getLink()
|
||||
{
|
||||
if ($file = $this->UploadedFile()) {
|
||||
if (trim($file->getFilename(), '/') != trim(ASSETS_DIR, '/')) {
|
||||
return $this->UploadedFile()->URL;
|
||||
@ -61,7 +65,8 @@ class SubmittedFileField extends SubmittedFormField {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName() {
|
||||
public function getFileName()
|
||||
{
|
||||
if ($this->UploadedFile()) {
|
||||
return $this->UploadedFile()->Name;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class SubmittedForm extends DataObject {
|
||||
class SubmittedForm extends DataObject
|
||||
{
|
||||
|
||||
private static $has_one = array(
|
||||
"SubmittedBy" => "Member",
|
||||
@ -29,7 +30,8 @@ class SubmittedForm extends DataObject {
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function relField($fieldName) {
|
||||
public function relField($fieldName)
|
||||
{
|
||||
// default case
|
||||
if ($value = parent::relField($fieldName)) {
|
||||
return $value;
|
||||
@ -49,8 +51,8 @@ class SubmittedForm extends DataObject {
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function getCMSFields() {
|
||||
|
||||
public function getCMSFields()
|
||||
{
|
||||
$self = $this;
|
||||
|
||||
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||
@ -82,7 +84,8 @@ class SubmittedForm extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||
if ($extended !== null) {
|
||||
return $extended;
|
||||
@ -95,7 +98,8 @@ class SubmittedForm extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||
if ($extended !== null) {
|
||||
return $extended;
|
||||
@ -108,7 +112,8 @@ class SubmittedForm extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||
if ($extended !== null) {
|
||||
return $extended;
|
||||
@ -121,7 +126,8 @@ class SubmittedForm extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
$extended = $this->extendedCan(__FUNCTION__, $member);
|
||||
if ($extended !== null) {
|
||||
return $extended;
|
||||
@ -135,7 +141,8 @@ class SubmittedForm extends DataObject {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function onBeforeDelete() {
|
||||
protected function onBeforeDelete()
|
||||
{
|
||||
if ($this->Values()) {
|
||||
foreach ($this->Values() as $value) {
|
||||
$value->delete();
|
||||
|
@ -5,7 +5,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class SubmittedFormField extends DataObject {
|
||||
class SubmittedFormField extends DataObject
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
"Name" => "Varchar",
|
||||
@ -27,7 +28,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canCreate($member = null) {
|
||||
public function canCreate($member = null)
|
||||
{
|
||||
return $this->Parent()->canCreate();
|
||||
}
|
||||
|
||||
@ -36,7 +38,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
public function canView($member = null)
|
||||
{
|
||||
return $this->Parent()->canView();
|
||||
}
|
||||
|
||||
@ -45,7 +48,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = null) {
|
||||
public function canEdit($member = null)
|
||||
{
|
||||
return $this->Parent()->canEdit();
|
||||
}
|
||||
|
||||
@ -54,7 +58,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function canDelete($member = null) {
|
||||
public function canDelete($member = null)
|
||||
{
|
||||
return $this->Parent()->canDelete();
|
||||
}
|
||||
|
||||
@ -65,7 +70,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedValue() {
|
||||
public function getFormattedValue()
|
||||
{
|
||||
return nl2br($this->dbObject('Value')->ATT());
|
||||
}
|
||||
|
||||
@ -75,7 +81,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return Text
|
||||
*/
|
||||
public function getExportValue() {
|
||||
public function getExportValue()
|
||||
{
|
||||
return $this->Value;
|
||||
}
|
||||
|
||||
@ -89,7 +96,8 @@ class SubmittedFormField extends DataObject {
|
||||
*
|
||||
* @return EditableFormField
|
||||
*/
|
||||
public function getEditableField() {
|
||||
public function getEditableField()
|
||||
{
|
||||
return $this->Parent()->Parent()->Fields()->filter(array(
|
||||
'Name' => $this->Name
|
||||
))->First();
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
use SilverStripe\Forms\SegmentFieldModifier\AbstractSegmentFieldModifier;
|
||||
|
||||
class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier {
|
||||
class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
@ -10,7 +11,8 @@ class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPreview($value) {
|
||||
public function getPreview($value)
|
||||
{
|
||||
if ($this->form instanceof Form && $record = $this->form->getRecord()) {
|
||||
$parent = $record->Parent();
|
||||
|
||||
@ -48,7 +50,8 @@ class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSuggestion($value) {
|
||||
public function getSuggestion($value)
|
||||
{
|
||||
return $this->getPreview($value);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;
|
||||
|
||||
class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier {
|
||||
class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
@ -10,7 +11,8 @@ class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPreview($value) {
|
||||
public function getPreview($value)
|
||||
{
|
||||
return str_replace('-', '_', parent::getPreview($value));
|
||||
}
|
||||
|
||||
@ -21,7 +23,8 @@ class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSuggestion($value) {
|
||||
public function getSuggestion($value)
|
||||
{
|
||||
return str_replace('-', '_', parent::getSuggestion($value));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserFormsColumnCleanTask extends MigrationTask {
|
||||
class UserFormsColumnCleanTask extends MigrationTask
|
||||
{
|
||||
|
||||
protected $title = "UserForms EditableFormField Column Clean task";
|
||||
|
||||
@ -22,7 +23,8 @@ class UserFormsColumnCleanTask extends MigrationTask {
|
||||
* Publish the existing forms.
|
||||
*
|
||||
*/
|
||||
public function run($request) {
|
||||
public function run($request)
|
||||
{
|
||||
foreach ($this->tables as $db) {
|
||||
$obj = new $db();
|
||||
$columns = $obj->database_fields($db);
|
||||
@ -57,5 +59,3 @@ class UserFormsColumnCleanTask extends MigrationTask {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,14 +3,16 @@
|
||||
/**
|
||||
* Service to support upgrade of userforms module
|
||||
*/
|
||||
class UserFormsUpgradeService {
|
||||
class UserFormsUpgradeService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $quiet;
|
||||
|
||||
public function run() {
|
||||
public function run()
|
||||
{
|
||||
$this->log("Upgrading formfield rules and custom settings");
|
||||
|
||||
// List of rules that have been created in all stages
|
||||
@ -25,7 +27,8 @@ class UserFormsUpgradeService {
|
||||
*
|
||||
* @param EditableFormField $field
|
||||
*/
|
||||
protected function upgradeField(EditableFormField $field) {
|
||||
protected function upgradeField(EditableFormField $field)
|
||||
{
|
||||
$this->log("Upgrading formfield ID = ".$field->ID);
|
||||
|
||||
// Check versions this field exists on
|
||||
@ -48,7 +51,8 @@ class UserFormsUpgradeService {
|
||||
* @param EditableFormField $field
|
||||
* @param stage $stage
|
||||
*/
|
||||
protected function upgradeFieldInStage(EditableFormField $field, $stage) {
|
||||
protected function upgradeFieldInStage(EditableFormField $field, $stage)
|
||||
{
|
||||
Versioned::reading_stage($stage);
|
||||
|
||||
// Migrate field rules
|
||||
@ -68,7 +72,8 @@ class UserFormsUpgradeService {
|
||||
* @param EditableFormField $field
|
||||
* @param string $stage
|
||||
*/
|
||||
protected function migrateRules(EditableFormField $field, $stage) {
|
||||
protected function migrateRules(EditableFormField $field, $stage)
|
||||
{
|
||||
$rulesData = $field->CustomRules
|
||||
? unserialize($field->CustomRules)
|
||||
: array();
|
||||
@ -106,7 +111,8 @@ class UserFormsUpgradeService {
|
||||
* @param EditableFormField $field
|
||||
* @param string $stage
|
||||
*/
|
||||
protected function migrateCustomSettings(EditableFormField $field, $stage) {
|
||||
protected function migrateCustomSettings(EditableFormField $field, $stage)
|
||||
{
|
||||
// Custom settings include:
|
||||
// - ExtraClass
|
||||
// - RightTitle
|
||||
@ -150,7 +156,8 @@ class UserFormsUpgradeService {
|
||||
* @param string $value
|
||||
* @return EditableCustomRule
|
||||
*/
|
||||
protected function findOrCreateRule(EditableFormField $field, $stage, $conditionOption, $display, $conditionFieldName, $value) {
|
||||
protected function findOrCreateRule(EditableFormField $field, $stage, $conditionOption, $display, $conditionFieldName, $value)
|
||||
{
|
||||
// Get id of field
|
||||
$conditionField = $conditionFieldName
|
||||
? EditableFormField::get()->filter('Name', $conditionFieldName)->first()
|
||||
@ -189,7 +196,8 @@ class UserFormsUpgradeService {
|
||||
return $rule;
|
||||
}
|
||||
|
||||
public function log($message) {
|
||||
public function log($message)
|
||||
{
|
||||
if ($this->getQuiet()) {
|
||||
return;
|
||||
}
|
||||
@ -206,13 +214,14 @@ class UserFormsUpgradeService {
|
||||
* @param bool $quiet
|
||||
* @return $ths
|
||||
*/
|
||||
public function setQuiet($quiet) {
|
||||
public function setQuiet($quiet)
|
||||
{
|
||||
$this->quiet = $quiet;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQuiet() {
|
||||
public function getQuiet()
|
||||
{
|
||||
return $this->quiet;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,13 +5,15 @@
|
||||
*
|
||||
* @author dmooyman
|
||||
*/
|
||||
class UserFormsUpgradeTask extends BuildTask {
|
||||
class UserFormsUpgradeTask extends BuildTask
|
||||
{
|
||||
|
||||
protected $title = "UserForms 3.0 Migration Tool";
|
||||
|
||||
protected $description = "Upgrade tool for sites upgrading to userforms 3.0";
|
||||
|
||||
public function run($request) {
|
||||
public function run($request)
|
||||
{
|
||||
$service = Injector::inst()->create('UserFormsUpgradeService');
|
||||
$service->log("Upgrading userforms module");
|
||||
$service->setQuiet(false)
|
||||
|
@ -10,7 +10,8 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserFormsVersionedTask extends MigrationTask {
|
||||
class UserFormsVersionedTask extends MigrationTask
|
||||
{
|
||||
|
||||
protected $title = "UserForms Versioned Initial Migration";
|
||||
|
||||
@ -20,7 +21,8 @@ class UserFormsVersionedTask extends MigrationTask {
|
||||
* Publish the existing forms.
|
||||
*
|
||||
*/
|
||||
public function run($request) {
|
||||
public function run($request)
|
||||
{
|
||||
$forms = Versioned::get_by_stage('UserDefinedForm', 'Live');
|
||||
|
||||
if ($forms) {
|
||||
@ -29,11 +31,8 @@ class UserFormsVersionedTask extends MigrationTask {
|
||||
$form->doPublish();
|
||||
}
|
||||
echo "Complete";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo "No Forms Found";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,11 +4,13 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableFormFieldTest extends FunctionalTest {
|
||||
class EditableFormFieldTest extends FunctionalTest
|
||||
{
|
||||
|
||||
static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
|
||||
public static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
|
||||
|
||||
function testFormFieldPermissions() {
|
||||
public function testFormFieldPermissions()
|
||||
{
|
||||
$text = $this->objFromFixture('EditableTextField', 'basic-text');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
@ -44,7 +46,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertFalse($text->canDelete());
|
||||
}
|
||||
|
||||
function testCustomRules() {
|
||||
public function testCustomRules()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
|
||||
|
||||
@ -73,7 +76,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
/**
|
||||
* @covers EditableOption::getValue
|
||||
*/
|
||||
public function testEditableOptionEmptyValue() {
|
||||
public function testEditableOptionEmptyValue()
|
||||
{
|
||||
$option = $this->objFromFixture('EditableOption', 'option-1');
|
||||
$option->Value = '';
|
||||
|
||||
@ -90,7 +94,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertEquals('', $option->Value);
|
||||
}
|
||||
|
||||
function testEditableDropdownField() {
|
||||
public function testEditableDropdownField()
|
||||
{
|
||||
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
|
||||
|
||||
$field = $dropdown->getFormField();
|
||||
@ -102,7 +107,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
|
||||
}
|
||||
|
||||
function testEditableRadioField() {
|
||||
public function testEditableRadioField()
|
||||
{
|
||||
$radio = $this->objFromFixture('EditableRadioField', 'radio-field');
|
||||
|
||||
$field = $radio->getFormField();
|
||||
@ -113,7 +119,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertEquals(array('Option 5' => 'Option 5', 'Option 6' => 'Option 6'), $values);
|
||||
}
|
||||
|
||||
function testMultipleOptionDuplication() {
|
||||
public function testMultipleOptionDuplication()
|
||||
{
|
||||
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
|
||||
|
||||
$clone = $dropdown->duplicate();
|
||||
@ -127,7 +134,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileField() {
|
||||
public function testFileField()
|
||||
{
|
||||
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
|
||||
$formField = $fileField->getFormField();
|
||||
|
||||
@ -135,7 +143,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertNotContains('notallowedextension', $formField->getValidator()->getAllowedExtensions());
|
||||
}
|
||||
|
||||
public function testFileFieldAllowedExtensionsBlacklist() {
|
||||
public function testFileFieldAllowedExtensionsBlacklist()
|
||||
{
|
||||
Config::inst()->update('EditableFileField', 'allowed_extensions_blacklist', array('jpg'));
|
||||
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
|
||||
$formField = $fileField->getFormField();
|
||||
@ -146,7 +155,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
/**
|
||||
* Verify that unique names are automatically generated for each formfield
|
||||
*/
|
||||
public function testUniqueName() {
|
||||
public function testUniqueName()
|
||||
{
|
||||
$textfield1 = new EditableTextField();
|
||||
$this->assertEmpty($textfield1->Name);
|
||||
|
||||
@ -164,7 +174,8 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertNotEquals($textfield1->Name, $textfield2->Name);
|
||||
}
|
||||
|
||||
public function testLengthRange() {
|
||||
public function testLengthRange()
|
||||
{
|
||||
/** @var EditableTextField $textField */
|
||||
$textField = $this->objFromFixture('EditableTextField', 'basic-text');
|
||||
|
||||
@ -193,6 +204,4 @@ class EditableFormFieldTest extends FunctionalTest {
|
||||
$this->assertEquals(10, $attributes['data-rule-minlength']);
|
||||
$this->assertEquals(20, $attributes['data-rule-maxlength']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,11 @@
|
||||
/**
|
||||
* Tests the {@see EditableLiteralField} class
|
||||
*/
|
||||
class EditableLiteralFieldTest extends SapphireTest {
|
||||
class EditableLiteralFieldTest extends SapphireTest
|
||||
{
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
HtmlEditorConfig::set_active('cms');
|
||||
}
|
||||
@ -13,7 +15,8 @@ class EditableLiteralFieldTest extends SapphireTest {
|
||||
/**
|
||||
* Tests the sanitisation of HTML content
|
||||
*/
|
||||
public function testSanitisation() {
|
||||
public function testSanitisation()
|
||||
{
|
||||
$rawContent = '<h1>Welcome</h1><script>alert("Hello!");</script><p>Giant Robots!</p>';
|
||||
$safeContent = '<h1>Welcome</h1><p>Giant Robots!</p>';
|
||||
$field = new EditableLiteralField();
|
||||
@ -29,7 +32,8 @@ class EditableLiteralFieldTest extends SapphireTest {
|
||||
$this->assertEquals($rawContent, $field->getContent());
|
||||
}
|
||||
|
||||
public function testHideLabel() {
|
||||
public function testHideLabel()
|
||||
{
|
||||
$field = new EditableLiteralField(array(
|
||||
'Title' => 'Test label'
|
||||
));
|
||||
|
@ -5,11 +5,13 @@
|
||||
*
|
||||
* @author dmooyman
|
||||
*/
|
||||
class SecureEditableFileFieldTest extends SapphireTest {
|
||||
class SecureEditableFileFieldTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected $usesDatabase = true;
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (!class_exists('SecureFileExtension')) {
|
||||
@ -20,12 +22,14 @@ class SecureEditableFileFieldTest extends SapphireTest {
|
||||
$this->clearPath();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
$this->clearPath();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function clearPath() {
|
||||
protected function clearPath()
|
||||
{
|
||||
if (file_exists(ASSETS_PATH . '/SecureEditableFileFieldTest')) {
|
||||
Filesystem::removeFolder(ASSETS_PATH . '/SecureEditableFileFieldTest');
|
||||
}
|
||||
@ -34,7 +38,8 @@ class SecureEditableFileFieldTest extends SapphireTest {
|
||||
/**
|
||||
* Test that newly created folders are secure
|
||||
*/
|
||||
public function testCreateFolder() {
|
||||
public function testCreateFolder()
|
||||
{
|
||||
$field = new EditableFileField();
|
||||
$field->write();
|
||||
$this->assertTrue($field->getIsSecure());
|
||||
@ -47,7 +52,8 @@ class SecureEditableFileFieldTest extends SapphireTest {
|
||||
/**
|
||||
* Test new folders that are created without security enabled
|
||||
*/
|
||||
public function testCreateInsecure() {
|
||||
public function testCreateInsecure()
|
||||
{
|
||||
Config::inst()->update('EditableFileField', 'disable_security', true);
|
||||
|
||||
// Esure folder is created without a folder
|
||||
|
@ -4,11 +4,13 @@
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
class UserDefinedFormControllerTest extends FunctionalTest
|
||||
{
|
||||
|
||||
static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
public static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
||||
public function testProcess() {
|
||||
public function testProcess()
|
||||
{
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
@ -60,7 +62,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->assertStringEndsWith('finished#uff', $response->getHeader('Location'));
|
||||
}
|
||||
|
||||
public function testValidation() {
|
||||
public function testValidation()
|
||||
{
|
||||
$form = $this->setupFormFrontend('email-form');
|
||||
|
||||
// Post with no fields
|
||||
@ -93,7 +96,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testFinished() {
|
||||
public function testFinished()
|
||||
{
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
// set formProcessed and SecurityID to replicate the form being filled out
|
||||
@ -105,7 +109,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->assertContains($form->OnCompleteMessage, $response->getBody());
|
||||
}
|
||||
|
||||
public function testAppendingFinished() {
|
||||
public function testAppendingFinished()
|
||||
{
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
// replicate finished being added to the end of the form URL without the form being filled out
|
||||
@ -117,7 +122,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->assertNotContains($form->OnCompleteMessage, $response->getBody());
|
||||
}
|
||||
|
||||
public function testForm() {
|
||||
public function testForm()
|
||||
{
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
@ -136,7 +142,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
|
||||
}
|
||||
|
||||
public function testGetFormFields() {
|
||||
public function testGetFormFields()
|
||||
{
|
||||
// generating the fieldset of fields
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
@ -205,7 +212,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->assertEquals($actions, $expected);
|
||||
}
|
||||
|
||||
public function testRenderingIntoFormTemplate() {
|
||||
public function testRenderingIntoFormTemplate()
|
||||
{
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
$form->Content = 'This is some content without a form nested between it';
|
||||
@ -220,7 +228,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$this->checkTemplateIsCorrect($parser);
|
||||
}
|
||||
|
||||
public function testRenderingIntoTemplateWithSubstringReplacement() {
|
||||
public function testRenderingIntoTemplateWithSubstringReplacement()
|
||||
{
|
||||
$form = $this->setupFormFrontend();
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
@ -237,7 +246,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
* @param string $fixtureName
|
||||
* @return UserDefinedForm
|
||||
*/
|
||||
protected function setupFormFrontend($fixtureName = 'basic-form-page') {
|
||||
protected function setupFormFrontend($fixtureName = 'basic-form-page')
|
||||
{
|
||||
$form = $this->objFromFixture('UserDefinedForm', $fixtureName);
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
@ -249,7 +259,8 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function checkTemplateIsCorrect($parser) {
|
||||
public function checkTemplateIsCorrect($parser)
|
||||
{
|
||||
$this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form'));
|
||||
|
||||
// check for the input
|
||||
@ -269,17 +280,20 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
class UserDefinedFormControllerTest_Controller extends UserDefinedForm_Controller implements TestOnly {
|
||||
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)
|
||||
*/
|
||||
public function Form() {
|
||||
public function Form()
|
||||
{
|
||||
$form = parent::Form();
|
||||
|
||||
if($form) $form->disableSecurityToken();
|
||||
if ($form) {
|
||||
$form->disableSecurityToken();
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,11 +3,13 @@
|
||||
/**
|
||||
* @package userforms
|
||||
*/
|
||||
class UserDefinedFormTest extends FunctionalTest {
|
||||
class UserDefinedFormTest extends FunctionalTest
|
||||
{
|
||||
|
||||
static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
public static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
||||
public function testRollbackToVersion() {
|
||||
public function testRollbackToVersion()
|
||||
{
|
||||
$this->markTestSkipped(
|
||||
'UserDefinedForm::rollback() has not been implemented completely'
|
||||
);
|
||||
@ -35,7 +37,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertEquals($orignal->SubmitButtonText, 'Button Text');
|
||||
}
|
||||
|
||||
public function testGetCMSFields() {
|
||||
public function testGetCMSFields()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
@ -47,7 +50,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
|
||||
}
|
||||
|
||||
public function testEmailRecipientPopup() {
|
||||
public function testEmailRecipientPopup()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
@ -83,7 +87,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$popup->delete();
|
||||
}
|
||||
|
||||
function testGetEmailBodyContent() {
|
||||
public function testGetEmailBodyContent()
|
||||
{
|
||||
$recipient = new UserDefinedForm_EmailRecipient();
|
||||
|
||||
$emailBody = 'not html';
|
||||
@ -104,7 +109,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$recipient->delete();
|
||||
}
|
||||
|
||||
function testGetEmailTemplateDropdownValues() {
|
||||
public function testGetEmailTemplateDropdownValues()
|
||||
{
|
||||
$recipient = new UserDefinedForm_EmailRecipient();
|
||||
|
||||
$defaultValues = array('SubmittedFormEmail' => 'SubmittedFormEmail');
|
||||
@ -112,7 +118,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertEquals($recipient->getEmailTemplateDropdownValues(), $defaultValues);
|
||||
}
|
||||
|
||||
function testEmailTemplateExists() {
|
||||
public function testEmailTemplateExists()
|
||||
{
|
||||
$recipient = new UserDefinedForm_EmailRecipient();
|
||||
|
||||
// Set the default template
|
||||
@ -128,7 +135,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$recipient->delete();
|
||||
}
|
||||
|
||||
function testCanEditAndDeleteRecipient() {
|
||||
public function testCanEditAndDeleteRecipient()
|
||||
{
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
@ -147,7 +155,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
function testPublishing() {
|
||||
public function testPublishing()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
@ -218,7 +227,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertEmpty($liveRule);
|
||||
}
|
||||
|
||||
function testUnpublishing() {
|
||||
public function testUnpublishing()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
$form->write();
|
||||
@ -238,7 +248,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertEquals(0, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value());
|
||||
}
|
||||
|
||||
function testDoRevertToLive() {
|
||||
public function testDoRevertToLive()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
$field = $form->Fields()->First();
|
||||
@ -264,7 +275,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertEquals('Title', $check->Title);
|
||||
}
|
||||
|
||||
function testDuplicatingForm() {
|
||||
public function testDuplicatingForm()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
@ -300,7 +312,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertNotEquals($form2GroupEnd->ID, $form3GroupStart->EndID);
|
||||
}
|
||||
|
||||
function testFormOptions() {
|
||||
public function testFormOptions()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
|
||||
@ -312,7 +325,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
$this->assertEquals($reset->Title(), 'Show Clear Form Button');
|
||||
}
|
||||
|
||||
public function testEmailRecipientFilters() {
|
||||
public function testEmailRecipientFilters()
|
||||
{
|
||||
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page');
|
||||
|
||||
// Check unfiltered recipients
|
||||
@ -405,7 +419,8 @@ class UserDefinedFormTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
public function testIndex() {
|
||||
public function testIndex()
|
||||
{
|
||||
// Test that the $UserDefinedForm is stripped out
|
||||
$page = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
|
||||
$page->publish('Stage', 'Live');
|
||||
|
@ -1,14 +1,16 @@
|
||||
<?php
|
||||
|
||||
|
||||
class UserFormTest extends SapphireTest {
|
||||
class UserFormTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected static $fixture_file = 'UserDefinedFormTest.yml';
|
||||
|
||||
/**
|
||||
* Tests that a form will not generate empty pages
|
||||
*/
|
||||
public function testEmptyPages() {
|
||||
public function testEmptyPages()
|
||||
{
|
||||
$page = $this->objFromFixture('UserDefinedForm', 'empty-page');
|
||||
$this->assertEquals(5, $page->Fields()->count());
|
||||
$controller = ModelAsController::controller_for($page);
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
class UserFormsUpgradeServiceTest extends SapphireTest {
|
||||
class UserFormsUpgradeServiceTest extends SapphireTest
|
||||
{
|
||||
|
||||
static $fixture_file = 'UserFormsUpgradeServiceTest.yml';
|
||||
public static $fixture_file = 'UserFormsUpgradeServiceTest.yml';
|
||||
|
||||
public function setUp() {
|
||||
public function setUp()
|
||||
{
|
||||
Config::inst()->update('UserDefinedForm', 'upgrade_on_build', false);
|
||||
parent::setUp();
|
||||
|
||||
@ -100,20 +102,21 @@ class UserFormsUpgradeServiceTest extends SapphireTest {
|
||||
'RightTitle' => 'Check this'
|
||||
));
|
||||
$checkbox1->write();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UserFormsUpgradeService;
|
||||
*/
|
||||
protected function getService() {
|
||||
protected function getService()
|
||||
{
|
||||
return singleton('UserFormsUpgradeService');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of custom rules
|
||||
*/
|
||||
public function testCustomRulesMigration() {
|
||||
public function testCustomRulesMigration()
|
||||
{
|
||||
$service = $this->getService();
|
||||
$service->setQuiet(true);
|
||||
$service->run();
|
||||
@ -140,7 +143,8 @@ class UserFormsUpgradeServiceTest extends SapphireTest {
|
||||
/**
|
||||
* Tests migration of all custom settings
|
||||
*/
|
||||
public function testCustomSettingsMigration() {
|
||||
public function testCustomSettingsMigration()
|
||||
{
|
||||
$service = $this->getService();
|
||||
$service->setQuiet(true);
|
||||
$service->run();
|
||||
|
Loading…
Reference in New Issue
Block a user