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