mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Convert to psr-2
This commit is contained in:
parent
e620576e97
commit
57048fd901
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(!defined('USERFORMS_DIR')) {
|
if (!defined('USERFORMS_DIR')) {
|
||||||
define('USERFORMS_DIR', basename(__DIR__));
|
define('USERFORMS_DIR', basename(__DIR__));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,16 +16,18 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($actionName === 'filter') {
|
if ($actionName === 'filter') {
|
||||||
$gridField->State->UserFormsGridField = array(
|
$gridField->State->UserFormsGridField = array(
|
||||||
'filter' => isset($data['FieldNameFilter']) ? $data['FieldNameFilter'] : null,
|
'filter' => isset($data['FieldNameFilter']) ? $data['FieldNameFilter'] : null,
|
||||||
'value' => isset($data['FieldValue']) ? $data['FieldValue'] : null,
|
'value' => isset($data['FieldValue']) ? $data['FieldValue'] : null,
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -72,7 +76,7 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
|||||||
$end = new DateField('EndFilter', _t('UserFormsGridFieldFilterHeader.TILL', 'Till'))
|
$end = new DateField('EndFilter', _t('UserFormsGridFieldFilterHeader.TILL', 'Till'))
|
||||||
)));
|
)));
|
||||||
|
|
||||||
foreach(array($start, $end) as $date) {
|
foreach (array($start, $end) as $date) {
|
||||||
$date->setConfig('showcalendar', true);
|
$date->setConfig('showcalendar', true);
|
||||||
$date->setConfig('dateformat', 'y-mm-dd');
|
$date->setConfig('dateformat', 'y-mm-dd');
|
||||||
$date->setConfig('datavalueformat', 'y-mm-dd');
|
$date->setConfig('datavalueformat', 'y-mm-dd');
|
||||||
@ -108,11 +112,12 @@ 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()) {
|
||||||
if(isset($filter['filter']) && $filter['filter'] && isset($filter['value']) && $filter['value']) {
|
if (isset($filter['filter']) && $filter['filter'] && isset($filter['value']) && $filter['value']) {
|
||||||
$dataList = $dataList->where(sprintf("
|
$dataList = $dataList->where(sprintf("
|
||||||
SELECT COUNT(*) FROM SubmittedFormField
|
SELECT COUNT(*) FROM SubmittedFormField
|
||||||
WHERE (
|
WHERE (
|
||||||
@ -126,13 +131,13 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($filter['start']) && $filter['start']) {
|
if (isset($filter['start']) && $filter['start']) {
|
||||||
$dataList = $dataList->filter(array(
|
$dataList = $dataList->filter(array(
|
||||||
'Created:GreaterThan' => $filter['start']
|
'Created:GreaterThan' => $filter['start']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($filter['end']) && $filter['end']) {
|
if (isset($filter['end']) && $filter['end']) {
|
||||||
$dataList = $dataList->filter(array(
|
$dataList = $dataList->filter(array(
|
||||||
'Created:LessThan' => $filter['end']
|
'Created:LessThan' => $filter['end']
|
||||||
));
|
));
|
||||||
|
@ -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,14 +29,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for necessary security module
|
// Check for necessary security module
|
||||||
if(!class_exists('SecureFileExtension')) {
|
if (!class_exists('SecureFileExtension')) {
|
||||||
trigger_error('SecureEditableFileField requires secureassets module', E_USER_WARNING);
|
trigger_error('SecureEditableFileField requires secureassets module', E_USER_WARNING);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -43,16 +45,17 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update all instances of editablefilefield which do NOT have a secure folder assigned
|
// Update all instances of editablefilefield which do NOT have a secure folder assigned
|
||||||
foreach(EditableFileField::get() as $fileField) {
|
foreach (EditableFileField::get() as $fileField) {
|
||||||
// Skip if secured
|
// Skip if secured
|
||||||
if($fileField->getIsSecure()) {
|
if ($fileField->getIsSecure()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,27 +71,28 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure folder exists
|
// Ensure folder exists
|
||||||
$folder = $this->owner->Folder();
|
$folder = $this->owner->Folder();
|
||||||
if(!$folder || !$folder->exists()) {
|
if (!$folder || !$folder->exists()) {
|
||||||
// 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,12 +130,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($folder->CanViewType) {
|
switch ($folder->CanViewType) {
|
||||||
case 'OnlyTheseUsers':
|
case 'OnlyTheseUsers':
|
||||||
return true;
|
return true;
|
||||||
case 'Inherit':
|
case 'Inherit':
|
||||||
|
@ -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();
|
||||||
@ -41,13 +44,13 @@ class UserFormFieldEditorExtension extends DataExtension {
|
|||||||
$editableColumns = new GridFieldEditableColumns();
|
$editableColumns = new GridFieldEditableColumns();
|
||||||
$fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
|
$fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
|
||||||
$editableColumns->setDisplayFields(array(
|
$editableColumns->setDisplayFields(array(
|
||||||
'ClassName' => function($record, $column, $grid) use ($fieldClasses) {
|
'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
|
||||||
if($record instanceof EditableFormField) {
|
if ($record instanceof EditableFormField) {
|
||||||
return $record->getInlineClassnameField($column, $fieldClasses);
|
return $record->getInlineClassnameField($column, $fieldClasses);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'Title' => function($record, $column, $grid) {
|
'Title' => function ($record, $column, $grid) {
|
||||||
if($record instanceof EditableFormField) {
|
if ($record instanceof EditableFormField) {
|
||||||
return $record->getInlineTitleField($column);
|
return $record->getInlineTitleField($column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,28 +91,29 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if first field is a step
|
// Check if first field is a step
|
||||||
$fields = $this->owner->Fields();
|
$fields = $this->owner->Fields();
|
||||||
$firstField = $fields->first();
|
$firstField = $fields->first();
|
||||||
if($firstField instanceof EditableFormStep) {
|
if ($firstField instanceof EditableFormStep) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't create steps on write if there are no formfields, as this
|
// Don't create steps on write if there are no formfields, as this
|
||||||
// can create duplicate first steps during publish of new records
|
// can create duplicate first steps during publish of new records
|
||||||
if(!$force && !$firstField) {
|
if (!$force && !$firstField) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-apply sort to each field starting at 2
|
// Re-apply sort to each field starting at 2
|
||||||
$next = 2;
|
$next = 2;
|
||||||
foreach($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$field->Sort = $next++;
|
$field->Sort = $next++;
|
||||||
$field->write();
|
$field->write();
|
||||||
}
|
}
|
||||||
@ -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,18 +140,19 @@ 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);
|
||||||
|
|
||||||
if($live) {
|
if ($live) {
|
||||||
foreach($live as $field) {
|
foreach ($live as $field) {
|
||||||
$field->doDeleteFromStage('Live');
|
$field->doDeleteFromStage('Live');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->owner->Fields() as $field) {
|
foreach ($this->owner->Fields() as $field) {
|
||||||
$field->doPublish('Stage', 'Live');
|
$field->doPublish('Stage', 'Live');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,8 +163,9 @@ 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,11 +176,12 @@ 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();
|
||||||
foreach($this->owner->Fields() as $field) {
|
foreach ($this->owner->Fields() as $field) {
|
||||||
$newField = $field->duplicate(false);
|
$newField = $field->duplicate(false);
|
||||||
$newField->ParentID = $newPage->ID;
|
$newField->ParentID = $newPage->ID;
|
||||||
$newField->ParentClass = $newPage->ClassName;
|
$newField->ParentClass = $newPage->ClassName;
|
||||||
@ -181,12 +189,12 @@ class UserFormFieldEditorExtension extends DataExtension {
|
|||||||
$newField->write();
|
$newField->write();
|
||||||
|
|
||||||
// If we encounter a group start, record it for later use
|
// If we encounter a group start, record it for later use
|
||||||
if($field instanceof EditableFieldGroup) {
|
if ($field instanceof EditableFieldGroup) {
|
||||||
$fieldGroups[$field->EndID] = $newField;
|
$fieldGroups[$field->EndID] = $newField;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we encounter an end group, link it back to the group start
|
// If we encounter an end group, link it back to the group start
|
||||||
if($field instanceof EditableFieldGroupEnd && isset($fieldGroups[$field->ID])) {
|
if ($field instanceof EditableFieldGroupEnd && isset($fieldGroups[$field->ID])) {
|
||||||
$groupStart = $fieldGroups[$field->ID];
|
$groupStart = $fieldGroups[$field->ID];
|
||||||
$groupStart->EndID = $newField->ID;
|
$groupStart->EndID = $newField->ID;
|
||||||
$groupStart->write();
|
$groupStart->write();
|
||||||
@ -209,10 +217,11 @@ class UserFormFieldEditorExtension extends DataExtension {
|
|||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function getIsModifiedOnStage($isModified) {
|
public function getIsModifiedOnStage($isModified)
|
||||||
if(!$isModified) {
|
{
|
||||||
foreach($this->owner->Fields() as $field) {
|
if (!$isModified) {
|
||||||
if($field->getIsModifiedOnStage()) {
|
foreach ($this->owner->Fields() as $field) {
|
||||||
|
if ($field->getIsModifiedOnStage()) {
|
||||||
$isModified = true;
|
$isModified = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -228,8 +237,9 @@ 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,14 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class UserFormValidator extends RequiredFields {
|
class UserFormValidator extends RequiredFields
|
||||||
public function php($data) {
|
{
|
||||||
if(!parent::php($data)) {
|
public function php($data)
|
||||||
|
{
|
||||||
|
if (!parent::php($data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip unsaved records
|
// Skip unsaved records
|
||||||
if(empty($data['ID']) || !is_numeric($data['ID'])) {
|
if (empty($data['ID']) || !is_numeric($data['ID'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,10 +19,10 @@ class UserFormValidator extends RequiredFields {
|
|||||||
// Current nesting
|
// Current nesting
|
||||||
$stack = array();
|
$stack = array();
|
||||||
$conditionalStep = false; // Is the current step conditional?
|
$conditionalStep = false; // Is the current step conditional?
|
||||||
foreach($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
if($field instanceof EditableFormStep) {
|
if ($field instanceof EditableFormStep) {
|
||||||
// Page at top level, or after another page is ok
|
// Page at top level, or after another page is ok
|
||||||
if(empty($stack) || (count($stack) === 1 && $stack[0] instanceof EditableFormStep)) {
|
if (empty($stack) || (count($stack) === 1 && $stack[0] instanceof EditableFormStep)) {
|
||||||
$stack = array($field);
|
$stack = array($field);
|
||||||
$conditionalStep = $field->EffectiveDisplayRules()->count() > 0;
|
$conditionalStep = $field->EffectiveDisplayRules()->count() > 0;
|
||||||
continue;
|
continue;
|
||||||
@ -42,7 +44,7 @@ class UserFormValidator extends RequiredFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate no pages
|
// Validate no pages
|
||||||
if(empty($stack)) {
|
if (empty($stack)) {
|
||||||
$this->validationError(
|
$this->validationError(
|
||||||
'FormFields',
|
'FormFields',
|
||||||
_t(
|
_t(
|
||||||
@ -58,17 +60,17 @@ class UserFormValidator extends RequiredFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Nest field group
|
// Nest field group
|
||||||
if($field instanceof EditableFieldGroup) {
|
if ($field instanceof EditableFieldGroup) {
|
||||||
$stack[] = $field;
|
$stack[] = $field;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unnest field group
|
// Unnest field group
|
||||||
if($field instanceof EditableFieldGroupEnd) {
|
if ($field instanceof EditableFieldGroupEnd) {
|
||||||
$top = end($stack);
|
$top = end($stack);
|
||||||
|
|
||||||
// Check that the top is a group at all
|
// Check that the top is a group at all
|
||||||
if(!$top instanceof EditableFieldGroup) {
|
if (!$top instanceof EditableFieldGroup) {
|
||||||
$this->validationError(
|
$this->validationError(
|
||||||
'FormFields',
|
'FormFields',
|
||||||
_t(
|
_t(
|
||||||
@ -84,7 +86,7 @@ class UserFormValidator extends RequiredFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that the top is the right group
|
// Check that the top is the right group
|
||||||
if($top->EndID != $field->ID) {
|
if ($top->EndID != $field->ID) {
|
||||||
$this->validationError(
|
$this->validationError(
|
||||||
'FormFields',
|
'FormFields',
|
||||||
_t(
|
_t(
|
||||||
@ -105,7 +107,7 @@ class UserFormValidator extends RequiredFields {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normal field type
|
// Normal field type
|
||||||
if($conditionalStep && $field->Required) {
|
if ($conditionalStep && $field->Required) {
|
||||||
$this->validationError(
|
$this->validationError(
|
||||||
'FormFields',
|
'FormFields',
|
||||||
_t(
|
_t(
|
||||||
|
@ -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,10 +12,11 @@ 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) {
|
||||||
$option->Name = "{$this->name}[]";
|
$option->Name = "{$this->name}[]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,24 +13,27 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip over fields that don't generate formfields
|
// Skip over fields that don't generate formfields
|
||||||
$formField = $field->getFormField();
|
$formField = $field->getFormField();
|
||||||
if(!$formField) {
|
if (!$formField) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +41,7 @@ abstract class UserFormsCompositeField extends CompositeField implements UserFor
|
|||||||
$this->push($formField);
|
$this->push($formField);
|
||||||
|
|
||||||
// Nest fields that are containers
|
// Nest fields that are containers
|
||||||
if($formField instanceof UserFormsFieldContainer) {
|
if ($formField instanceof UserFormsFieldContainer) {
|
||||||
return $formField->setParent($this);
|
return $formField->setParent($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,41 +3,45 @@
|
|||||||
/**
|
/**
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->push($formField);
|
$this->push($formField);
|
||||||
|
|
||||||
if($formField instanceof UserFormsFieldContainer) {
|
if ($formField instanceof UserFormsFieldContainer) {
|
||||||
return $formField->setParent($this);
|
return $formField->setParent($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
{
|
||||||
if($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
|
foreach ($this as $field) {
|
||||||
|
if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
|
||||||
$this->remove($field);
|
$this->remove($field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,25 @@
|
|||||||
/**
|
/**
|
||||||
* 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,15 +130,16 @@ 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) {
|
||||||
$classes = array($grid->getModelClass());
|
$classes = array($grid->getModelClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out classes without permission
|
// Filter out classes without permission
|
||||||
return array_filter($classes, function($class) {
|
return array_filter($classes, function ($class) {
|
||||||
return singleton($class)->canCreate();
|
return singleton($class)->canCreate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -139,23 +149,25 @@ 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()) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get button name
|
// Get button name
|
||||||
$buttonName = $this->getButtonName();
|
$buttonName = $this->getButtonName();
|
||||||
if(!$buttonName) {
|
if (!$buttonName) {
|
||||||
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
|
||||||
$objectName = $singleton->i18n_singular_name();
|
$objectName = $singleton->i18n_singular_name();
|
||||||
$buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
|
$buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
|
||||||
@ -170,7 +182,7 @@ class GridFieldAddClassesButton extends Object implements GridField_HTMLProvider
|
|||||||
);
|
);
|
||||||
$addAction->setAttribute('data-icon', 'add');
|
$addAction->setAttribute('data-icon', 'add');
|
||||||
|
|
||||||
if($this->getButtonClass()) {
|
if ($this->getButtonClass()) {
|
||||||
$addAction->addExtraClass($this->getButtonClass());
|
$addAction->addExtraClass($this->getButtonClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,12 +206,14 @@ 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);
|
||||||
default:
|
default:
|
||||||
@ -212,15 +227,16 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add item to gridfield
|
// Add item to gridfield
|
||||||
$list = $grid->getList();
|
$list = $grid->getList();
|
||||||
foreach($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
$item = $class::create();
|
$item = $class::create();
|
||||||
$item->write();
|
$item->write();
|
||||||
$list->add($item);
|
$list->add($item);
|
||||||
|
@ -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);
|
||||||
|
|
||||||
@ -32,17 +33,17 @@ class UserForm extends Form {
|
|||||||
|
|
||||||
// Number each page
|
// Number each page
|
||||||
$stepNumber = 1;
|
$stepNumber = 1;
|
||||||
foreach($this->getSteps() as $step) {
|
foreach ($this->getSteps() as $step) {
|
||||||
$step->setStepNumber($stepNumber++);
|
$step->setStepNumber($stepNumber++);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($controller->DisableCsrfSecurityToken) {
|
if ($controller->DisableCsrfSecurityToken) {
|
||||||
$this->disableSecurityToken();
|
$this->disableSecurityToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = Session::get("FormInfo.{$this->FormName()}.data");
|
$data = Session::get("FormInfo.{$this->FormName()}.data");
|
||||||
|
|
||||||
if(is_array($data)) {
|
if (is_array($data)) {
|
||||||
$this->loadDataFrom($data);
|
$this->loadDataFrom($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class UserForm extends Form {
|
|||||||
public function setupFormErrors()
|
public function setupFormErrors()
|
||||||
{
|
{
|
||||||
// Suppress setupFormErrors if fields haven't been bootstrapped
|
// Suppress setupFormErrors if fields haven't been bootstrapped
|
||||||
if($this->fields && $this->fields->exists()) {
|
if ($this->fields && $this->fields->exists()) {
|
||||||
return parent::setupFormErrors();
|
return parent::setupFormErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,8 +83,9 @@ 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');
|
||||||
|
|
||||||
@ -124,7 +130,7 @@ class UserForm extends Form {
|
|||||||
new FormAction("process", $submitText)
|
new FormAction("process", $submitText)
|
||||||
);
|
);
|
||||||
|
|
||||||
if($this->controller->ShowClearButton) {
|
if ($this->controller->ShowClearButton) {
|
||||||
$actions->push(new ResetFormAction("clearForm", $clearText));
|
$actions->push(new ResetFormAction("clearForm", $clearText));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,10 +97,11 @@ 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) {
|
||||||
return $parent->canEdit($member);
|
return $parent->canEdit($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,13 +115,14 @@ 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'];
|
||||||
}
|
}
|
||||||
// Hack in currently edited page if context is missing
|
// Hack in currently edited page if context is missing
|
||||||
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
||||||
return Controller::curr()->currentPage();
|
return Controller::curr()->currentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,12 +118,13 @@ 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;
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function($fields) use ($self) {
|
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
|
||||||
|
|
||||||
// define tabs
|
// define tabs
|
||||||
$fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
|
$fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
|
||||||
@ -131,8 +133,8 @@ class UserDefinedForm extends Page {
|
|||||||
|
|
||||||
// text to show on complete
|
// text to show on complete
|
||||||
$onCompleteFieldSet = new CompositeField(
|
$onCompleteFieldSet = new CompositeField(
|
||||||
$label = new LabelField('OnCompleteMessageLabel',_t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
|
$label = new LabelField('OnCompleteMessageLabel', _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
|
||||||
$editor = new HtmlEditorField( 'OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
|
$editor = new HtmlEditorField('OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
|
||||||
);
|
);
|
||||||
|
|
||||||
$onCompleteFieldSet->addExtraClass('field');
|
$onCompleteFieldSet->addExtraClass('field');
|
||||||
@ -185,7 +187,7 @@ ORDER BY "Sort", "Title"
|
|||||||
SQL;
|
SQL;
|
||||||
// Sanitise periods in title
|
// Sanitise periods in title
|
||||||
$columns = array();
|
$columns = array();
|
||||||
foreach(DB::query($columnSQL)->map() as $name => $title) {
|
foreach (DB::query($columnSQL)->map() as $name => $title) {
|
||||||
$columns[$name] = trim(strtr($title, '.', ' '));
|
$columns[$name] = trim(strtr($title, '.', ' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +208,7 @@ SQL;
|
|||||||
/**
|
/**
|
||||||
* Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
|
* Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
|
||||||
*/
|
*/
|
||||||
if(class_exists('GridFieldBulkManager')) {
|
if (class_exists('GridFieldBulkManager')) {
|
||||||
$config->addComponent(new GridFieldBulkManager());
|
$config->addComponent(new GridFieldBulkManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +237,7 @@ SQL;
|
|||||||
|
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
if($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
|
if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
|
||||||
$fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
|
$fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
|
||||||
"<p class=\"message warning\">" . _t("UserDefinedForm.NORECIPIENTS",
|
"<p class=\"message warning\">" . _t("UserDefinedForm.NORECIPIENTS",
|
||||||
"Warning: You have not configured any recipients. Form submissions may be missed.")
|
"Warning: You have not configured any recipients. Form submissions may be missed.")
|
||||||
@ -253,11 +255,12 @@ 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
|
||||||
$recipients = $recipients->filterByCallback(function($recipient) use ($data, $form) {
|
$recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
|
||||||
return $recipient->canSend($data, $form);
|
return $recipient->canSend($data, $form);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -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,14 +301,16 @@ 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) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
@ -360,13 +369,13 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
Requirements::javascript(
|
Requirements::javascript(
|
||||||
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
|
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
|
||||||
);
|
);
|
||||||
if($this->HideFieldLabels) {
|
if ($this->HideFieldLabels) {
|
||||||
Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
|
Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind a confirmation message when navigating away from a partially completed form.
|
// Bind a confirmation message when navigating away from a partially completed form.
|
||||||
$page = $this->data();
|
$page = $this->data();
|
||||||
if($page::config()->enable_are_you_sure) {
|
if ($page::config()->enable_are_you_sure) {
|
||||||
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
|
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,10 +387,11 @@ 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) {
|
||||||
$content = preg_replace('/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
|
$content = preg_replace('/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
|
||||||
return array(
|
return array(
|
||||||
'Content' => DBField::create_field('HTMLText', $content),
|
'Content' => DBField::create_field('HTMLText', $content),
|
||||||
@ -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,30 +434,31 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function generateConditionalJavascript() {
|
public function generateConditionalJavascript()
|
||||||
|
{
|
||||||
$default = "";
|
$default = "";
|
||||||
$rules = "";
|
$rules = "";
|
||||||
|
|
||||||
$watch = array();
|
$watch = array();
|
||||||
$watchLoad = array();
|
$watchLoad = array();
|
||||||
|
|
||||||
if($this->Fields()) {
|
if ($this->Fields()) {
|
||||||
foreach($this->Fields() as $field) {
|
foreach ($this->Fields() as $field) {
|
||||||
$holderSelector = $field->getSelectorHolder();
|
$holderSelector = $field->getSelectorHolder();
|
||||||
|
|
||||||
// Is this Field Show by Default
|
// Is this Field Show by Default
|
||||||
if(!$field->ShowOnLoad) {
|
if (!$field->ShowOnLoad) {
|
||||||
$default .= "{$holderSelector}.hide().trigger('userform.field.hide');\n";
|
$default .= "{$holderSelector}.hide().trigger('userform.field.hide');\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for field dependencies / default
|
// Check for field dependencies / default
|
||||||
foreach($field->EffectiveDisplayRules() as $rule) {
|
foreach ($field->EffectiveDisplayRules() as $rule) {
|
||||||
|
|
||||||
// Get the field which is effected
|
// Get the field which is effected
|
||||||
$formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
|
$formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
|
||||||
|
|
||||||
// Skip deleted fields
|
// Skip deleted fields
|
||||||
if(!$formFieldWatch) {
|
if (!$formFieldWatch) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +473,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
// @todo encapulsation
|
// @todo encapulsation
|
||||||
$action = "change";
|
$action = "change";
|
||||||
|
|
||||||
if($formFieldWatch instanceof EditableTextField) {
|
if ($formFieldWatch instanceof EditableTextField) {
|
||||||
$action = "keyup";
|
$action = "keyup";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,15 +481,15 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
$checkboxField = false;
|
$checkboxField = false;
|
||||||
$radioField = false;
|
$radioField = false;
|
||||||
|
|
||||||
if(in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) {
|
if (in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) {
|
||||||
$action = "click";
|
$action = "click";
|
||||||
$checkboxField = true;
|
$checkboxField = true;
|
||||||
} else if ($formFieldWatch->ClassName == "EditableRadioField") {
|
} elseif ($formFieldWatch->ClassName == "EditableRadioField") {
|
||||||
$radioField = true;
|
$radioField = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// and what should we evaluate
|
// and what should we evaluate
|
||||||
switch($rule->ConditionOption) {
|
switch ($rule->ConditionOption) {
|
||||||
case 'IsNotBlank':
|
case 'IsNotBlank':
|
||||||
$expression = ($checkboxField || $radioField) ? '$(this).is(":checked")' :'$(this).val() != ""';
|
$expression = ($checkboxField || $radioField) ? '$(this).is(":checked")' :'$(this).val() != ""';
|
||||||
|
|
||||||
@ -488,7 +501,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
case 'HasValue':
|
case 'HasValue':
|
||||||
if ($checkboxField) {
|
if ($checkboxField) {
|
||||||
$expression = '$(this).prop("checked")';
|
$expression = '$(this).prop("checked")';
|
||||||
} else if ($radioField) {
|
} elseif ($radioField) {
|
||||||
// We cannot simply get the value of the radio group, we need to find the checked option first.
|
// We cannot simply get the value of the radio group, we need to find the checked option first.
|
||||||
$expression = '$(this).parents(".field, .control-group").find("input:checked").val()=="'. $rule->FieldValue .'"';
|
$expression = '$(this).parents(".field, .control-group").find("input:checked").val()=="'. $rule->FieldValue .'"';
|
||||||
} else {
|
} else {
|
||||||
@ -515,7 +528,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
default: // ==HasNotValue
|
default: // ==HasNotValue
|
||||||
if ($checkboxField) {
|
if ($checkboxField) {
|
||||||
$expression = '!$(this).prop("checked")';
|
$expression = '!$(this).prop("checked")';
|
||||||
} else if ($radioField) {
|
} elseif ($radioField) {
|
||||||
// We cannot simply get the value of the radio group, we need to find the checked option first.
|
// We cannot simply get the value of the radio group, we need to find the checked option first.
|
||||||
$expression = '$(this).parents(".field, .control-group").find("input:checked").val()!="'. $rule->FieldValue .'"';
|
$expression = '$(this).parents(".field, .control-group").find("input:checked").val()!="'. $rule->FieldValue .'"';
|
||||||
} else {
|
} else {
|
||||||
@ -525,7 +538,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($watch[$fieldToWatch])) {
|
if (!isset($watch[$fieldToWatch])) {
|
||||||
$watch[$fieldToWatch] = array();
|
$watch[$fieldToWatch] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,12 +555,12 @@ class UserDefinedForm_Controller extends Page_Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($watch) {
|
if ($watch) {
|
||||||
foreach($watch as $key => $values) {
|
foreach ($watch as $key => $values) {
|
||||||
$logic = array();
|
$logic = array();
|
||||||
$actions = array();
|
$actions = array();
|
||||||
|
|
||||||
foreach($values as $rule) {
|
foreach ($values as $rule) {
|
||||||
// Assign action
|
// Assign action
|
||||||
$actions[$rule['action']] = $rule['action'];
|
$actions[$rule['action']] = $rule['action'];
|
||||||
|
|
||||||
@ -576,7 +589,7 @@ EOS;
|
|||||||
$logic\n
|
$logic\n
|
||||||
}); \n
|
}); \n
|
||||||
});\n";
|
});\n";
|
||||||
foreach($actions as $action) {
|
foreach ($actions as $action) {
|
||||||
$rules .= $key.".$action(function() {
|
$rules .= $key.".$action(function() {
|
||||||
$(this).data('userformConditions').call(this);\n
|
$(this).data('userformConditions').call(this);\n
|
||||||
});\n";
|
});\n";
|
||||||
@ -584,8 +597,8 @@ EOS;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($watchLoad) {
|
if ($watchLoad) {
|
||||||
foreach($watchLoad as $key => $value) {
|
foreach ($watchLoad as $key => $value) {
|
||||||
$rules .= $key.".each(function() {
|
$rules .= $key.".each(function() {
|
||||||
$(this).data('userformConditions').call(this);\n
|
$(this).data('userformConditions').call(this);\n
|
||||||
});\n";
|
});\n";
|
||||||
@ -593,7 +606,7 @@ EOS;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only add customScript if $default or $rules is defined
|
// Only add customScript if $default or $rules is defined
|
||||||
if($default || $rules) {
|
if ($default || $rules) {
|
||||||
Requirements::customScript(<<<JS
|
Requirements::customScript(<<<JS
|
||||||
(function($) {
|
(function($) {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
@ -617,21 +630,22 @@ 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;
|
||||||
|
|
||||||
// if saving is not disabled save now to generate the ID
|
// if saving is not disabled save now to generate the ID
|
||||||
if(!$this->DisableSaveSubmissions) {
|
if (!$this->DisableSaveSubmissions) {
|
||||||
$submittedForm->write();
|
$submittedForm->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
$attachments = array();
|
$attachments = array();
|
||||||
$submittedFields = new ArrayList();
|
$submittedFields = new ArrayList();
|
||||||
|
|
||||||
foreach($this->Fields() as $field) {
|
foreach ($this->Fields() as $field) {
|
||||||
if(!$field->showInReports()) {
|
if (!$field->showInReports()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,17 +655,17 @@ JS
|
|||||||
$submittedField->Title = $field->getField('Title');
|
$submittedField->Title = $field->getField('Title');
|
||||||
|
|
||||||
// save the value from the data
|
// save the value from the data
|
||||||
if($field->hasMethod('getValueFromData')) {
|
if ($field->hasMethod('getValueFromData')) {
|
||||||
$submittedField->Value = $field->getValueFromData($data);
|
$submittedField->Value = $field->getValueFromData($data);
|
||||||
} else {
|
} else {
|
||||||
if(isset($data[$field->Name])) {
|
if (isset($data[$field->Name])) {
|
||||||
$submittedField->Value = $data[$field->Name];
|
$submittedField->Value = $data[$field->Name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($data[$field->Name])) {
|
if (!empty($data[$field->Name])) {
|
||||||
if(in_array("EditableFileField", $field->getClassAncestry())) {
|
if (in_array("EditableFileField", $field->getClassAncestry())) {
|
||||||
if(isset($_FILES[$field->Name])) {
|
if (isset($_FILES[$field->Name])) {
|
||||||
$foldername = $field->getFormField()->getFolderName();
|
$foldername = $field->getFormField()->getFolderName();
|
||||||
|
|
||||||
// create the file from post data
|
// create the file from post data
|
||||||
@ -660,7 +674,7 @@ JS
|
|||||||
$file->ShowInSearch = 0;
|
$file->ShowInSearch = 0;
|
||||||
try {
|
try {
|
||||||
$upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
|
$upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
|
||||||
} catch( ValidationException $e ) {
|
} catch (ValidationException $e) {
|
||||||
$validationResult = $e->getResult();
|
$validationResult = $e->getResult();
|
||||||
$form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
|
$form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
|
||||||
Controller::curr()->redirectBack();
|
Controller::curr()->redirectBack();
|
||||||
@ -671,7 +685,7 @@ JS
|
|||||||
$submittedField->UploadedFileID = $file->ID;
|
$submittedField->UploadedFileID = $file->ID;
|
||||||
|
|
||||||
// attach a file only if lower than 1MB
|
// attach a file only if lower than 1MB
|
||||||
if($file->getAbsoluteSize() < 1024*1024*1) {
|
if ($file->getAbsoluteSize() < 1024*1024*1) {
|
||||||
$attachments[] = $file;
|
$attachments[] = $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -680,7 +694,7 @@ JS
|
|||||||
|
|
||||||
$submittedField->extend('onPopulationFromField', $field);
|
$submittedField->extend('onPopulationFromField', $field);
|
||||||
|
|
||||||
if(!$this->DisableSaveSubmissions) {
|
if (!$this->DisableSaveSubmissions) {
|
||||||
$submittedField->write();
|
$submittedField->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,15 +709,14 @@ JS
|
|||||||
$this->extend('updateEmailData', $emailData, $attachments);
|
$this->extend('updateEmailData', $emailData, $attachments);
|
||||||
|
|
||||||
// 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']);
|
||||||
|
|
||||||
if($attachments) {
|
if ($attachments) {
|
||||||
foreach($attachments as $file) {
|
foreach ($attachments as $file) {
|
||||||
if($file->ID != 0) {
|
if ($file->ID != 0) {
|
||||||
$email->attachFile(
|
$email->attachFile(
|
||||||
$file->Filename,
|
$file->Filename,
|
||||||
$file->Filename,
|
$file->Filename,
|
||||||
@ -726,50 +739,49 @@ JS
|
|||||||
$email->setTo($recipient->EmailAddress);
|
$email->setTo($recipient->EmailAddress);
|
||||||
$email->setSubject($recipient->EmailSubject);
|
$email->setSubject($recipient->EmailSubject);
|
||||||
|
|
||||||
if($recipient->EmailReplyTo) {
|
if ($recipient->EmailReplyTo) {
|
||||||
$email->setReplyTo($recipient->EmailReplyTo);
|
$email->setReplyTo($recipient->EmailReplyTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if they are a dynamic reply to. eg based on a email field a user selected
|
// check to see if they are a dynamic reply to. eg based on a email field a user selected
|
||||||
if($recipient->SendEmailFromField()) {
|
if ($recipient->SendEmailFromField()) {
|
||||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
|
||||||
|
|
||||||
if($submittedFormField && is_string($submittedFormField->Value)) {
|
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
||||||
$email->setReplyTo($submittedFormField->Value);
|
$email->setReplyTo($submittedFormField->Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
||||||
if($recipient->SendEmailToField()) {
|
if ($recipient->SendEmailToField()) {
|
||||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
||||||
|
|
||||||
if($submittedFormField && is_string($submittedFormField->Value)) {
|
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
||||||
$email->setTo($submittedFormField->Value);
|
$email->setTo($submittedFormField->Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if there is a dynamic subject
|
// check to see if there is a dynamic subject
|
||||||
if($recipient->SendEmailSubjectField()) {
|
if ($recipient->SendEmailSubjectField()) {
|
||||||
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
|
||||||
|
|
||||||
if($submittedFormField && trim($submittedFormField->Value)) {
|
if ($submittedFormField && trim($submittedFormField->Value)) {
|
||||||
$email->setSubject($submittedFormField->Value);
|
$email->setSubject($submittedFormField->Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('updateEmail', $email, $recipient, $emailData);
|
$this->extend('updateEmail', $email, $recipient, $emailData);
|
||||||
|
|
||||||
if($recipient->SendPlain) {
|
if ($recipient->SendPlain) {
|
||||||
$body = strip_tags($recipient->getEmailBodyContent()) . "\n";
|
$body = strip_tags($recipient->getEmailBodyContent()) . "\n";
|
||||||
if(isset($emailData['Fields']) && !$recipient->HideFormData) {
|
if (isset($emailData['Fields']) && !$recipient->HideFormData) {
|
||||||
foreach($emailData['Fields'] as $Field) {
|
foreach ($emailData['Fields'] as $Field) {
|
||||||
$body .= $Field->Title .': '. $Field->Value ." \n";
|
$body .= $Field->Title .': '. $Field->Value ." \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$email->setBody($body);
|
$email->setBody($body);
|
||||||
$email->sendPlain();
|
$email->sendPlain();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$email->send();
|
$email->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -784,22 +796,22 @@ JS
|
|||||||
|
|
||||||
// set a session variable from the security ID to stop people accessing
|
// set a session variable from the security ID to stop people accessing
|
||||||
// the finished method directly.
|
// the finished method directly.
|
||||||
if(!$this->DisableAuthenicatedFinishAction) {
|
if (!$this->DisableAuthenicatedFinishAction) {
|
||||||
if (isset($data['SecurityID'])) {
|
if (isset($data['SecurityID'])) {
|
||||||
Session::set('FormProcessed',$data['SecurityID']);
|
Session::set('FormProcessed', $data['SecurityID']);
|
||||||
} else {
|
} else {
|
||||||
// if the form has had tokens disabled we still need to set FormProcessed
|
// if the form has had tokens disabled we still need to set FormProcessed
|
||||||
// to allow us to get through the finshed method
|
// to allow us to get through the finshed method
|
||||||
if (!$this->Form()->getSecurityToken()->isEnabled()) {
|
if (!$this->Form()->getSecurityToken()->isEnabled()) {
|
||||||
$randNum = rand(1, 1000);
|
$randNum = rand(1, 1000);
|
||||||
$randHash = md5($randNum);
|
$randHash = md5($randNum);
|
||||||
Session::set('FormProcessed',$randHash);
|
Session::set('FormProcessed', $randHash);
|
||||||
Session::set('FormProcessedNum',$randNum);
|
Session::set('FormProcessedNum', $randNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->DisableSaveSubmissions) {
|
if (!$this->DisableSaveSubmissions) {
|
||||||
Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
|
Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,16 +841,17 @@ 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) {
|
||||||
$submission = SubmittedForm::get()->byId($submission);
|
$submission = SubmittedForm::get()->byId($submission);
|
||||||
}
|
}
|
||||||
|
|
||||||
$referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
|
$referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
|
||||||
|
|
||||||
if(!$this->DisableAuthenicatedFinishAction) {
|
if (!$this->DisableAuthenicatedFinishAction) {
|
||||||
$formProcessed = Session::get('FormProcessed');
|
$formProcessed = Session::get('FormProcessed');
|
||||||
|
|
||||||
if (!isset($formProcessed)) {
|
if (!isset($formProcessed)) {
|
||||||
|
@ -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,15 +44,17 @@ 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'];
|
||||||
unset($data['Default']);
|
unset($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,16 +29,17 @@ 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;
|
||||||
|
|
||||||
if($entries) {
|
if ($entries) {
|
||||||
if(!is_array($data[$this->Name])) {
|
if (!is_array($data[$this->Name])) {
|
||||||
$entries = array($data[$this->Name]);
|
$entries = array($data[$this->Name]);
|
||||||
}
|
}
|
||||||
foreach($entries as $selected => $value) {
|
foreach ($entries as $selected => $value) {
|
||||||
if(!$result) {
|
if (!$result) {
|
||||||
$result = $value;
|
$result = $value;
|
||||||
} else {
|
} else {
|
||||||
$result .= ", " . $value;
|
$result .= ", " . $value;
|
||||||
@ -46,10 +49,11 @@ 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) {
|
||||||
return "$(\"input[name='{$this->Name}[]'][value='{$rule->FieldValue}']\")";
|
return "$(\"input[name='{$this->Name}[]'][value='{$rule->FieldValue}']\")";
|
||||||
} else {
|
} else {
|
||||||
return "$(\"input[name='{$this->Name}[]']:first\")";
|
return "$(\"input[name='{$this->Name}[]']:first\")";
|
||||||
|
@ -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,8 +21,9 @@ 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',
|
||||||
CheckboxField::create(
|
CheckboxField::create(
|
||||||
@ -39,12 +41,13 @@ 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;
|
||||||
|
|
||||||
$field = EditableDateField_FormField::create( $this->Name, $this->EscapedTitle, $defaultValue)
|
$field = EditableDateField_FormField::create($this->Name, $this->EscapedTitle, $defaultValue)
|
||||||
->setConfig('showcalendar', true)
|
->setConfig('showcalendar', true)
|
||||||
->setFieldHolderTemplate('UserFormsField_holder')
|
->setFieldHolderTemplate('UserFormsField_holder')
|
||||||
->setTemplate('UserFormsField');
|
->setTemplate('UserFormsField');
|
||||||
@ -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,21 +29,23 @@ 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');
|
||||||
|
|
||||||
// Set default
|
// Set default
|
||||||
$defaultOption = $this->getDefaultOptions()->first();
|
$defaultOption = $this->getDefaultOptions()->first();
|
||||||
if($defaultOption) {
|
if ($defaultOption) {
|
||||||
$field->setValue($defaultOption->EscapedTitle);
|
$field->setValue($defaultOption->EscapedTitle);
|
||||||
}
|
}
|
||||||
$this->doUpdateFormField($field);
|
$this->doUpdateFormField($field);
|
||||||
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,8 +18,9 @@ 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',
|
||||||
TextField::create(
|
TextField::create(
|
||||||
@ -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,12 +54,13 @@ 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);
|
||||||
|
|
||||||
if($this->Placeholder) {
|
if ($this->Placeholder) {
|
||||||
$field->setAttribute('placeholder', $this->Placeholder);
|
$field->setAttribute('placeholder', $this->Placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,33 +66,35 @@ 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
|
||||||
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
if(($end = $this->End()) && $end->exists()) {
|
if (($end = $this->End()) && $end->exists()) {
|
||||||
$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,35 +38,41 @@ 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
|
||||||
// with no end attached
|
// with no end attached
|
||||||
$group = $this->Group();
|
$group = $this->Group();
|
||||||
if(!($group && $group->exists()) && $this->ParentID) {
|
if (!($group && $group->exists()) && $this->ParentID) {
|
||||||
$group = EditableFieldGroup::get()
|
$group = EditableFieldGroup::get()
|
||||||
->filter(array(
|
->filter(array(
|
||||||
'ParentID' => $this->ParentID,
|
'ParentID' => $this->ParentID,
|
||||||
@ -75,20 +83,20 @@ class EditableFieldGroupEnd extends EditableFormField {
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
// When a group is found, attach it to this end
|
// When a group is found, attach it to this end
|
||||||
if($group) {
|
if ($group) {
|
||||||
$group->EndID = $this->ID;
|
$group->EndID = $this->ID;
|
||||||
$group->write();
|
$group->write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onAfterDelete() {
|
protected function onAfterDelete()
|
||||||
|
{
|
||||||
parent::onAfterDelete();
|
parent::onAfterDelete();
|
||||||
|
|
||||||
// Delete group
|
// Delete group
|
||||||
if(($group = $this->Group()) && $group->exists()) {
|
if (($group = $this->Group()) && $group->exists()) {
|
||||||
$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');
|
||||||
@ -65,9 +68,9 @@ class EditableFileField extends EditableFormField {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$folder = $this->Folder();
|
$folder = $this->Folder();
|
||||||
if($folder && $folder->exists()) {
|
if ($folder && $folder->exists()) {
|
||||||
$field->setFolderName(
|
$field->setFolderName(
|
||||||
preg_replace("/^assets\//","", $folder->Filename)
|
preg_replace("/^assets\//", "", $folder->Filename)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,18 +86,21 @@ 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'];
|
||||||
unset($data['Folder']);
|
unset($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
|
||||||
@ -181,7 +185,7 @@ class EditableFormField extends DataObject {
|
|||||||
// Custom settings
|
// Custom settings
|
||||||
if (!empty(self::$allowed_css)) {
|
if (!empty(self::$allowed_css)) {
|
||||||
$cssList = array();
|
$cssList = array();
|
||||||
foreach(self::$allowed_css as $k => $v) {
|
foreach (self::$allowed_css as $k => $v) {
|
||||||
if (!is_array($v)) {
|
if (!is_array($v)) {
|
||||||
$cssList[$k]=$v;
|
$cssList[$k]=$v;
|
||||||
} elseif ($k === $this->ClassName) {
|
} elseif ($k === $this->ClassName) {
|
||||||
@ -213,13 +217,13 @@ class EditableFormField extends DataObject {
|
|||||||
|
|
||||||
// Validation
|
// Validation
|
||||||
$validationFields = $this->getFieldValidationOptions();
|
$validationFields = $this->getFieldValidationOptions();
|
||||||
if($validationFields && $validationFields->count()) {
|
if ($validationFields && $validationFields->count()) {
|
||||||
$fields->addFieldsToTab('Root.Validation', $validationFields);
|
$fields->addFieldsToTab('Root.Validation', $validationFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add display rule fields
|
// Add display rule fields
|
||||||
$displayFields = $this->getDisplayRuleFields();
|
$displayFields = $this->getDisplayRuleFields();
|
||||||
if($displayFields && $displayFields->count()) {
|
if ($displayFields && $displayFields->count()) {
|
||||||
$fields->addFieldsToTab('Root.DisplayRules', $displayFields);
|
$fields->addFieldsToTab('Root.DisplayRules', $displayFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,9 +237,10 @@ 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(
|
||||||
LabelField::create(_t(
|
LabelField::create(_t(
|
||||||
'EditableFormField.DISPLAY_RULES_DISABLED',
|
'EditableFormField.DISPLAY_RULES_DISABLED',
|
||||||
@ -249,7 +254,7 @@ class EditableFormField extends DataObject {
|
|||||||
$editableColumns = new GridFieldEditableColumns();
|
$editableColumns = new GridFieldEditableColumns();
|
||||||
$editableColumns->setDisplayFields(array(
|
$editableColumns->setDisplayFields(array(
|
||||||
'Display' => '',
|
'Display' => '',
|
||||||
'ConditionFieldID' => function($record, $column, $grid) use ($allowedClasses, $self) {
|
'ConditionFieldID' => function ($record, $column, $grid) use ($allowedClasses, $self) {
|
||||||
return DropdownField::create(
|
return DropdownField::create(
|
||||||
$column,
|
$column,
|
||||||
'',
|
'',
|
||||||
@ -264,14 +269,14 @@ class EditableFormField extends DataObject {
|
|||||||
->map('ID', 'Title')
|
->map('ID', 'Title')
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'ConditionOption' => function($record, $column, $grid) {
|
'ConditionOption' => function ($record, $column, $grid) {
|
||||||
$options = Config::inst()->get('EditableCustomRule', 'condition_options');
|
$options = Config::inst()->get('EditableCustomRule', 'condition_options');
|
||||||
return DropdownField::create($column, '', $options);
|
return DropdownField::create($column, '', $options);
|
||||||
},
|
},
|
||||||
'FieldValue' => function($record, $column, $grid) {
|
'FieldValue' => function ($record, $column, $grid) {
|
||||||
return TextField::create($column);
|
return TextField::create($column);
|
||||||
},
|
},
|
||||||
'ParentID' => function($record, $column, $grid) use ($self) {
|
'ParentID' => function ($record, $column, $grid) use ($self) {
|
||||||
return HiddenField::create($column, '', $self->ID);
|
return HiddenField::create($column, '', $self->ID);
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@ -301,19 +306,19 @@ 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"');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->Sort && $this->ParentID) {
|
if (!$this->Sort && $this->ParentID) {
|
||||||
$parentID = $this->ParentID;
|
$parentID = $this->ParentID;
|
||||||
$this->Sort = EditableFormField::get()
|
$this->Sort = EditableFormField::get()
|
||||||
->filter('ParentID', $parentID)
|
->filter('ParentID', $parentID)
|
||||||
@ -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);
|
||||||
@ -335,7 +341,7 @@ class EditableFormField extends DataObject {
|
|||||||
|
|
||||||
// Check if it conflicts
|
// Check if it conflicts
|
||||||
$exists = EditableFormField::get()->filter('Name', $name)->count() > 0;
|
$exists = EditableFormField::get()->filter('Name', $name)->count() > 0;
|
||||||
} while($exists);
|
} while ($exists);
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,23 +374,22 @@ 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();
|
||||||
} else if (!$this->exists() && Controller::has_curr()) {
|
} elseif (!$this->exists() && Controller::has_curr()) {
|
||||||
// This is for GridFieldOrderableRows support as it checks edit permissions on
|
// This is for GridFieldOrderableRows support as it checks edit permissions on
|
||||||
// singleton of the class. Allows editing of User Defined Form pages by
|
// singleton of the class. Allows editing of User Defined Form pages by
|
||||||
// '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,9 +406,10 @@ 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,10 +423,11 @@ 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) {
|
||||||
return $parent->canEdit($member);
|
return $parent->canEdit($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,13 +441,14 @@ 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'];
|
||||||
}
|
}
|
||||||
// Hack in currently edited page if context is missing
|
// Hack in currently edited page if context is missing
|
||||||
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
||||||
return Controller::curr()->currentPage();
|
return Controller::curr()->currentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,12 +591,13 @@ 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();
|
||||||
if(isset($settings) && count($settings) > 0) {
|
if (isset($settings) && count($settings) > 0) {
|
||||||
if(isset($settings[$setting])) {
|
if (isset($settings[$setting])) {
|
||||||
return $settings[$setting];
|
return $settings[$setting];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,45 +654,48 @@ 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;
|
||||||
}
|
}
|
||||||
// Check parent
|
// Check parent
|
||||||
$form = $this->Parent();
|
$form = $this->Parent();
|
||||||
if(!$form || !$form->exists() || !($fields = $form->Fields())) {
|
if (!$form || !$form->exists() || !($fields = $form->Fields())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$prior = 0; // Number of prior group at this level
|
$prior = 0; // Number of prior group at this level
|
||||||
$stack = array(); // Current stack of nested groups, where the top level = the page
|
$stack = array(); // Current stack of nested groups, where the top level = the page
|
||||||
foreach($fields->map('ID', 'ClassName') as $id => $className) {
|
foreach ($fields->map('ID', 'ClassName') as $id => $className) {
|
||||||
if($className === 'EditableFormStep') {
|
if ($className === 'EditableFormStep') {
|
||||||
$priorPage = empty($stack) ? $prior : $stack[0];
|
$priorPage = empty($stack) ? $prior : $stack[0];
|
||||||
$stack = array($priorPage + 1);
|
$stack = array($priorPage + 1);
|
||||||
$prior = 0;
|
$prior = 0;
|
||||||
} elseif($className === 'EditableFieldGroup') {
|
} elseif ($className === 'EditableFieldGroup') {
|
||||||
$stack[] = $prior + 1;
|
$stack[] = $prior + 1;
|
||||||
$prior = 0;
|
$prior = 0;
|
||||||
} elseif($className === 'EditableFieldGroupEnd') {
|
} elseif ($className === 'EditableFieldGroupEnd') {
|
||||||
$prior = array_pop($stack);
|
$prior = array_pop($stack);
|
||||||
}
|
}
|
||||||
if($id == $this->ID) {
|
if ($id == $this->ID) {
|
||||||
return implode('.', $stack);
|
return implode('.', $stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,11 +717,12 @@ 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')),
|
||||||
TextField::create('CustomErrorMessage', _t('EditableFormField.CUSTOMERROR','Custom Error Message'))
|
TextField::create('CustomErrorMessage', _t('EditableFormField.CUSTOMERROR', 'Custom Error Message'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->extend('updateFieldValidationOptions', $fields);
|
$this->extend('updateFieldValidationOptions', $fields);
|
||||||
@ -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,32 +758,33 @@ 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());
|
||||||
|
|
||||||
// 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
|
||||||
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this field is required add some
|
// if this field is required add some
|
||||||
if($this->Required) {
|
if ($this->Required) {
|
||||||
// Required validation can conflict so add the Required validation messages as input attributes
|
// Required validation can conflict so add the Required validation messages as input attributes
|
||||||
$errorMessage = $this->getErrorMessage()->HTML();
|
$errorMessage = $this->getErrorMessage()->HTML();
|
||||||
$field->addExtraClass('requiredField');
|
$field->addExtraClass('requiredField');
|
||||||
$field->setAttribute('data-rule-required', 'true');
|
$field->setAttribute('data-rule-required', 'true');
|
||||||
$field->setAttribute('data-msg-required', $errorMessage);
|
$field->setAttribute('data-msg-required', $errorMessage);
|
||||||
|
|
||||||
if($identifier = UserDefinedForm::config()->required_identifier) {
|
if ($identifier = UserDefinedForm::config()->required_identifier) {
|
||||||
$title = $field->Title() . " <span class='required-identifier'>". $identifier . "</span>";
|
$title = $field->Title() . " <span class='required-identifier'>". $identifier . "</span>";
|
||||||
$field->setTitle($title);
|
$field->setTitle($title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,16 +833,17 @@ 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');
|
||||||
unset($data['ShowOnLoad']);
|
unset($data['ShowOnLoad']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate all other settings
|
// Migrate all other settings
|
||||||
foreach($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if($this->hasField($key)) {
|
if ($this->hasField($key)) {
|
||||||
$this->setField($key, $value);
|
$this->setField($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,24 +902,25 @@ 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.
|
||||||
$editableFieldClasses = array();
|
$editableFieldClasses = array();
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
// Skip abstract / hidden classes
|
// Skip abstract / hidden classes
|
||||||
if(Config::inst()->get($class, 'abstract', Config::UNINHERITED) || Config::inst()->get($class, 'hidden')
|
if (Config::inst()->get($class, 'abstract', Config::UNINHERITED) || Config::inst()->get($class, 'hidden')
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$includeLiterals && Config::inst()->get($class, 'literal')) {
|
if (!$includeLiterals && Config::inst()->get($class, 'literal')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$singleton = singleton($class);
|
$singleton = singleton($class);
|
||||||
if(!$singleton->canCreate()) {
|
if (!$singleton->canCreate()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,29 +23,31 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip unsaved records
|
// Skip unsaved records
|
||||||
if(!$this->record || !$this->record->exists()) {
|
if (!$this->record || !$this->record->exists()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip validation if not required
|
// Skip validation if not required
|
||||||
if(empty($data['Required'])) {
|
if (empty($data['Required'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip validation if no rules
|
// Skip validation if no rules
|
||||||
$count = EditableCustomRule::get()->filter('ParentID', $this->record->ID)->count();
|
$count = EditableCustomRule::get()->filter('ParentID', $this->record->ID)->count();
|
||||||
if($count == 0) {
|
if ($count == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,31 +66,36 @@ 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
|
||||||
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
||||||
}
|
}
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,9 +43,10 @@ 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,11 +124,12 @@ 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;
|
||||||
if(empty($this->Title) || $this->HideLabel) {
|
if (empty($this->Title) || $this->HideLabel) {
|
||||||
$classes .= " nolabel";
|
$classes .= " nolabel";
|
||||||
} else {
|
} else {
|
||||||
$label = "<label class='left'>{$this->EscapedTitle}</label>";
|
$label = "<label class='left'>{$this->EscapedTitle}</label>";
|
||||||
@ -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,8 +38,9 @@ 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,8 +50,9 @@ 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);
|
||||||
return $member ? $member->getName() : "";
|
return $member ? $member->getName() : "";
|
||||||
|
@ -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,26 +31,27 @@ 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();
|
||||||
$editableColumns->setDisplayFields(array(
|
$editableColumns->setDisplayFields(array(
|
||||||
'Title' => array(
|
'Title' => array(
|
||||||
'title' => _t('EditableMultipleOptionField.TITLE', 'Title'),
|
'title' => _t('EditableMultipleOptionField.TITLE', 'Title'),
|
||||||
'callback' => function($record, $column, $grid) {
|
'callback' => function ($record, $column, $grid) {
|
||||||
return TextField::create($column);
|
return TextField::create($column);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
'Value' => array(
|
'Value' => array(
|
||||||
'title' => _t('EditableMultipleOptionField.VALUE', 'Value'),
|
'title' => _t('EditableMultipleOptionField.VALUE', 'Value'),
|
||||||
'callback' => function($record, $column, $grid) {
|
'callback' => function ($record, $column, $grid) {
|
||||||
return TextField::create($column);
|
return TextField::create($column);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
'Default' => array(
|
'Default' => array(
|
||||||
'title' => _t('EditableMultipleOptionField.DEFAULT', 'Selected by default?'),
|
'title' => _t('EditableMultipleOptionField.DEFAULT', 'Selected by default?'),
|
||||||
'callback' => function($record, $column, $grid) {
|
'callback' => function ($record, $column, $grid) {
|
||||||
return CheckboxField::create($column);
|
return CheckboxField::create($column);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -73,7 +75,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
|||||||
$optionsConfig
|
$optionsConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
$fields->insertAfter(new Tab('Options', _t('EditableMultipleOptionField.OPTIONSTAB','Options')), 'Main');
|
$fields->insertAfter(new Tab('Options', _t('EditableMultipleOptionField.OPTIONSTAB', 'Options')), 'Main');
|
||||||
$fields->addFieldToTab('Root.Options', $optionsGrid);
|
$fields->addFieldToTab('Root.Options', $optionsGrid);
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
@ -87,17 +89,18 @@ 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) {
|
||||||
foreach($live as $option) {
|
foreach ($live as $option) {
|
||||||
$option->delete();
|
$option->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->Options()) {
|
if ($this->Options()) {
|
||||||
foreach($this->Options() as $option) {
|
foreach ($this->Options() as $option) {
|
||||||
$option->publish($fromStage, $toStage, $createNewVersion);
|
$option->publish($fromStage, $toStage, $createNewVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,11 +115,12 @@ 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);
|
||||||
foreach($options as $option) {
|
foreach ($options as $option) {
|
||||||
$option->deleteFromStage($stage);
|
$option->deleteFromStage($stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +133,12 @@ class EditableMultipleOptionField extends EditableFormField {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete()
|
||||||
|
{
|
||||||
$options = $this->Options();
|
$options = $this->Options();
|
||||||
|
|
||||||
if($options) {
|
if ($options) {
|
||||||
foreach($options as $option) {
|
foreach ($options as $option) {
|
||||||
$option->delete();
|
$option->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,10 +152,11 @@ 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) {
|
||||||
$newField = $field->duplicate(false);
|
$newField = $field->duplicate(false);
|
||||||
$newField->ParentID = $clonedNode->ID;
|
$newField->ParentID = $clonedNode->ID;
|
||||||
$newField->Version = 0;
|
$newField->Version = 0;
|
||||||
@ -166,7 +172,8 @@ class EditableMultipleOptionField extends EditableFormField {
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getHasAddableOptions() {
|
public function getHasAddableOptions()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,10 +182,11 @@ 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) {
|
||||||
return $optionMap->toArray();
|
return $optionMap->toArray();
|
||||||
}
|
}
|
||||||
return $optionMap;
|
return $optionMap;
|
||||||
@ -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,12 +20,14 @@ 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',
|
||||||
TextField::create(
|
TextField::create(
|
||||||
@ -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,18 +74,19 @@ 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) {
|
||||||
$field->setAttribute('data-rule-min', $this->MinValue);
|
$field->setAttribute('data-rule-min', $this->MinValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->MaxValue) {
|
if ($this->MaxValue) {
|
||||||
$field->setAttribute('data-rule-max', $this->MaxValue);
|
$field->setAttribute('data-rule-max', $this->MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->Placeholder) {
|
if ($this->Placeholder) {
|
||||||
$field->setAttribute('placeholder', $this->Placeholder);
|
$field->setAttribute('placeholder', $this->Placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,10 +96,11 @@ 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) {
|
||||||
return $parent->canEdit($member);
|
return $parent->canEdit($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,13 +114,14 @@ 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'];
|
||||||
}
|
}
|
||||||
// Hack in currently edited page if context is missing
|
// Hack in currently edited page if context is missing
|
||||||
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
||||||
return Controller::curr()->currentPage();
|
return Controller::curr()->currentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +156,7 @@ class EditableOption extends DataObject {
|
|||||||
public function getValue()
|
public function getValue()
|
||||||
{
|
{
|
||||||
$value = $this->getField('Value');
|
$value = $this->getField('Value');
|
||||||
if(empty($value) && !self::allow_empty_values()) {
|
if (empty($value) && !self::allow_empty_values()) {
|
||||||
return $this->Title;
|
return $this->Title;
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -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,20 +26,22 @@ 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');
|
||||||
|
|
||||||
// Set default item
|
// Set default item
|
||||||
$defaultOption = $this->getDefaultOptions()->first();
|
$defaultOption = $this->getDefaultOptions()->first();
|
||||||
if($defaultOption) {
|
if ($defaultOption) {
|
||||||
$field->setValue($defaultOption->EscapedTitle);
|
$field->setValue($defaultOption->EscapedTitle);
|
||||||
}
|
}
|
||||||
$this->doUpdateFormField($field);
|
$this->doUpdateFormField($field);
|
||||||
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,8 +25,9 @@ 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',
|
||||||
NumericField::create(
|
NumericField::create(
|
||||||
@ -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,8 +75,9 @@ 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')
|
||||||
->setTemplate('UserFormsTextareaField')
|
->setTemplate('UserFormsTextareaField')
|
||||||
@ -94,21 +98,22 @@ 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) {
|
||||||
$field->setAttribute('data-rule-minlength', intval($this->MinLength));
|
$field->setAttribute('data-rule-minlength', intval($this->MinLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_numeric($this->MaxLength) && $this->MaxLength > 0) {
|
if (is_numeric($this->MaxLength) && $this->MaxLength > 0) {
|
||||||
if($field instanceof TextField) {
|
if ($field instanceof TextField) {
|
||||||
$field->setMaxLength(intval($this->MaxLength));
|
$field->setMaxLength(intval($this->MaxLength));
|
||||||
}
|
}
|
||||||
$field->setAttribute('data-rule-maxlength', intval($this->MaxLength));
|
$field->setAttribute('data-rule-maxlength', intval($this->MaxLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->Placeholder) {
|
if ($this->Placeholder) {
|
||||||
$field->setAttribute('placeholder', $this->Placeholder);
|
$field->setAttribute('placeholder', $this->Placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,15 +51,16 @@ 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');
|
||||||
}
|
}
|
||||||
if(isset($fields['EmailSubject'])) {
|
if (isset($fields['EmailSubject'])) {
|
||||||
$fields['EmailSubject'] = _t('UserDefinedForm.EMAILSUBJECT', 'Subject');
|
$fields['EmailSubject'] = _t('UserDefinedForm.EMAILSUBJECT', 'Subject');
|
||||||
}
|
}
|
||||||
if(isset($fields['EmailFrom'])) {
|
if (isset($fields['EmailFrom'])) {
|
||||||
$fields['EmailFrom'] = _t('UserDefinedForm.EMAILFROM', 'From');
|
$fields['EmailFrom'] = _t('UserDefinedForm.EMAILFROM', 'From');
|
||||||
}
|
}
|
||||||
return $fields;
|
return $fields;
|
||||||
@ -69,18 +71,20 @@ 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;
|
||||||
}
|
}
|
||||||
if($this->EmailSubject) {
|
if ($this->EmailSubject) {
|
||||||
return $this->EmailSubject;
|
return $this->EmailSubject;
|
||||||
}
|
}
|
||||||
return parent::getTitle();
|
return parent::getTitle();
|
||||||
@ -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()
|
||||||
@ -104,14 +109,14 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
|||||||
);
|
);
|
||||||
|
|
||||||
$columns->setDisplayFields(array(
|
$columns->setDisplayFields(array(
|
||||||
'ConditionFieldID' => function($record, $column, $grid) use ($formFields) {
|
'ConditionFieldID' => function ($record, $column, $grid) use ($formFields) {
|
||||||
return DropdownField::create($column, false, $formFields->map('ID', 'Title'));
|
return DropdownField::create($column, false, $formFields->map('ID', 'Title'));
|
||||||
},
|
},
|
||||||
'ConditionOption' => function($record, $column, $grid) {
|
'ConditionOption' => function ($record, $column, $grid) {
|
||||||
$options = UserDefinedForm_EmailRecipientCondition::config()->condition_options;
|
$options = UserDefinedForm_EmailRecipientCondition::config()->condition_options;
|
||||||
return DropdownField::create($column, false, $options);
|
return DropdownField::create($column, false, $options);
|
||||||
},
|
},
|
||||||
'ConditionValue' => function($record, $column, $grid) {
|
'ConditionValue' => function ($record, $column, $grid) {
|
||||||
return TextField::create($column);
|
return TextField::create($column);
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@ -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
|
||||||
@ -145,7 +151,7 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
|||||||
|
|
||||||
|
|
||||||
// Check valid email-recipient fields
|
// Check valid email-recipient fields
|
||||||
if($this->config()->allow_unbound_recipient_fields) {
|
if ($this->config()->allow_unbound_recipient_fields) {
|
||||||
// To address can only be email fields or multi option fields
|
// To address can only be email fields or multi option fields
|
||||||
$validEmailToFields = ArrayList::create($validEmailFromFields->toArray());
|
$validEmailToFields = ArrayList::create($validEmailFromFields->toArray());
|
||||||
$validEmailToFields->merge($multiOptionFields);
|
$validEmailToFields->merge($multiOptionFields);
|
||||||
@ -181,7 +187,7 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
|||||||
$validEmailToFields->map('ID', 'Title')
|
$validEmailToFields->map('ID', 'Title')
|
||||||
)->setEmptyString(' ')
|
)->setEmptyString(' ')
|
||||||
)
|
)
|
||||||
->setTitle(_t('UserDefinedForm.SENDEMAILTO','Send email to'))
|
->setTitle(_t('UserDefinedForm.SENDEMAILTO', 'Send email to'))
|
||||||
->setDescription(_t(
|
->setDescription(_t(
|
||||||
'UserDefinedForm.SENDEMAILTO_DESCRIPTION',
|
'UserDefinedForm.SENDEMAILTO_DESCRIPTION',
|
||||||
'You may enter multiple email addresses as a comma separated list.'
|
'You may enter multiple email addresses as a comma separated list.'
|
||||||
@ -189,7 +195,7 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
|||||||
|
|
||||||
|
|
||||||
// From
|
// From
|
||||||
TextField::create('EmailFrom', _t('UserDefinedForm.FROMADDRESS','Send email from'))
|
TextField::create('EmailFrom', _t('UserDefinedForm.FROMADDRESS', 'Send email from'))
|
||||||
->setDescription(_t(
|
->setDescription(_t(
|
||||||
'UserDefinedForm.EmailFromContent',
|
'UserDefinedForm.EmailFromContent',
|
||||||
"The from address allows you to set who the email comes from. On most servers this ".
|
"The from address allows you to set who the email comes from. On most servers this ".
|
||||||
@ -248,9 +254,9 @@ class UserDefinedForm_EmailRecipient extends DataObject {
|
|||||||
_t('UserDefinedForm.EMAILTEMPLATE', 'Email template'),
|
_t('UserDefinedForm.EMAILTEMPLATE', 'Email template'),
|
||||||
$this->getEmailTemplateDropdownValues()
|
$this->getEmailTemplateDropdownValues()
|
||||||
)->addExtraClass('toggle-html-only'),
|
)->addExtraClass('toggle-html-only'),
|
||||||
HTMLEditorField::create('EmailBodyHtml', _t('UserDefinedForm.EMAILBODYHTML','Body'))
|
HTMLEditorField::create('EmailBodyHtml', _t('UserDefinedForm.EMAILBODYHTML', 'Body'))
|
||||||
->addExtraClass('toggle-html-only'),
|
->addExtraClass('toggle-html-only'),
|
||||||
TextareaField::create('EmailBody', _t('UserDefinedForm.EMAILBODY','Body'))
|
TextareaField::create('EmailBody', _t('UserDefinedForm.EMAILBODY', 'Body'))
|
||||||
->addExtraClass('toggle-plain-only'),
|
->addExtraClass('toggle-plain-only'),
|
||||||
LiteralField::create(
|
LiteralField::create(
|
||||||
'EmailPreview',
|
'EmailPreview',
|
||||||
@ -296,10 +302,11 @@ 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) {
|
||||||
return $parent->canEdit($member);
|
return $parent->canEdit($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,13 +320,14 @@ 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'];
|
||||||
}
|
}
|
||||||
// Hack in currently edited page if context is missing
|
// Hack in currently edited page if context is missing
|
||||||
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
||||||
return Controller::curr()->currentPage();
|
return Controller::curr()->currentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,21 +372,22 @@ 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()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all rules
|
// Check all rules
|
||||||
$isAnd = $this->CustomRulesCondition === 'And';
|
$isAnd = $this->CustomRulesCondition === 'And';
|
||||||
foreach($customRules as $customRule) {
|
foreach ($customRules as $customRule) {
|
||||||
$matches = $customRule->matches($data, $form);
|
$matches = $customRule->matches($data, $form);
|
||||||
if($isAnd && !$matches) {
|
if ($isAnd && !$matches) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!$isAnd && $matches) {
|
if (!$isAnd && $matches) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,10 +39,11 @@ 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) {
|
||||||
case 'IsBlank':
|
case 'IsBlank':
|
||||||
return empty($fieldValue);
|
return empty($fieldValue);
|
||||||
case 'IsNotBlank':
|
case 'IsNotBlank':
|
||||||
@ -61,10 +63,11 @@ 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) {
|
||||||
return $parent->canEdit($member);
|
return $parent->canEdit($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,13 +81,14 @@ 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'];
|
||||||
}
|
}
|
||||||
// Hack in currently edited page if context is missing
|
// Hack in currently edited page if context is missing
|
||||||
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
||||||
return Controller::curr()->currentPage();
|
return Controller::curr()->currentPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,12 +20,13 @@ 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');
|
||||||
|
|
||||||
if($link) {
|
if ($link) {
|
||||||
return DBField::create_field('HTMLText', sprintf(
|
return DBField::create_field('HTMLText', sprintf(
|
||||||
'%s - <a href="%s" target="_blank">%s</a>',
|
'%s - <a href="%s" target="_blank">%s</a>',
|
||||||
$name, $link, $title
|
$name, $link, $title
|
||||||
@ -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,9 +51,10 @@ class SubmittedFileField extends SubmittedFormField {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLink() {
|
public function getLink()
|
||||||
if($file = $this->UploadedFile()) {
|
{
|
||||||
if(trim($file->getFilename(), '/') != trim(ASSETS_DIR,'/')) {
|
if ($file = $this->UploadedFile()) {
|
||||||
|
if (trim($file->getFilename(), '/') != trim(ASSETS_DIR, '/')) {
|
||||||
return $this->UploadedFile()->URL;
|
return $this->UploadedFile()->URL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,8 +65,9 @@ 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,9 +30,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ class SubmittedForm extends DataObject {
|
|||||||
'Name' => $fieldName
|
'Name' => $fieldName
|
||||||
))->first();
|
))->first();
|
||||||
|
|
||||||
if($formField) {
|
if ($formField) {
|
||||||
return $formField->getFormattedValue();
|
return $formField->getFormattedValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,11 +51,11 @@ 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) {
|
||||||
$fields->removeByName('Values');
|
$fields->removeByName('Values');
|
||||||
$fields->dataFieldByName('SubmittedByID')->setDisabled(true);
|
$fields->dataFieldByName('SubmittedByID')->setDisabled(true);
|
||||||
|
|
||||||
@ -82,9 +84,10 @@ 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;
|
||||||
}
|
}
|
||||||
return $this->Parent()->canCreate();
|
return $this->Parent()->canCreate();
|
||||||
@ -95,9 +98,10 @@ 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;
|
||||||
}
|
}
|
||||||
return $this->Parent()->canView();
|
return $this->Parent()->canView();
|
||||||
@ -108,9 +112,10 @@ 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;
|
||||||
}
|
}
|
||||||
return $this->Parent()->canEdit();
|
return $this->Parent()->canEdit();
|
||||||
@ -121,9 +126,10 @@ 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;
|
||||||
}
|
}
|
||||||
return $this->Parent()->canDelete();
|
return $this->Parent()->canDelete();
|
||||||
@ -135,9 +141,10 @@ class SubmittedForm extends DataObject {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function onBeforeDelete() {
|
protected function onBeforeDelete()
|
||||||
if($this->Values()) {
|
{
|
||||||
foreach($this->Values() as $value) {
|
if ($this->Values()) {
|
||||||
|
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,8 +11,9 @@ 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();
|
||||||
|
|
||||||
$try = $value;
|
$try = $value;
|
||||||
@ -24,7 +26,7 @@ class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier {
|
|||||||
|
|
||||||
$counter = 1;
|
$counter = 1;
|
||||||
|
|
||||||
while($sibling !== null) {
|
while ($sibling !== null) {
|
||||||
$try = $value . '_' . $counter++;
|
$try = $value . '_' . $counter++;
|
||||||
|
|
||||||
$sibling = EditableformField::get()
|
$sibling = EditableformField::get()
|
||||||
@ -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,19 +3,21 @@
|
|||||||
/**
|
/**
|
||||||
* 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
|
||||||
$fields = Versioned::get_including_deleted('EditableFormField');
|
$fields = Versioned::get_including_deleted('EditableFormField');
|
||||||
foreach($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$this->upgradeField($field);
|
$this->upgradeField($field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
@ -33,11 +36,11 @@ class UserFormsUpgradeService {
|
|||||||
$stageField = Versioned::get_one_by_stage('EditableFormField', 'Stage', $filter);
|
$stageField = Versioned::get_one_by_stage('EditableFormField', 'Stage', $filter);
|
||||||
$liveField = Versioned::get_one_by_stage('EditableFormField', 'Live', $filter);
|
$liveField = Versioned::get_one_by_stage('EditableFormField', 'Live', $filter);
|
||||||
|
|
||||||
if($stageField) {
|
if ($stageField) {
|
||||||
$this->upgradeFieldInStage($stageField, 'Stage');
|
$this->upgradeFieldInStage($stageField, 'Stage');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($liveField) {
|
if ($liveField) {
|
||||||
$this->upgradeFieldInStage($liveField, 'Live');
|
$this->upgradeFieldInStage($liveField, 'Live');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,19 +72,20 @@ 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();
|
||||||
|
|
||||||
// Skip blank rules or fields with custom rules already
|
// Skip blank rules or fields with custom rules already
|
||||||
if(empty($rulesData) || $field->DisplayRules()->count()) {
|
if (empty($rulesData) || $field->DisplayRules()->count()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check value of this condition
|
// Check value of this condition
|
||||||
foreach($rulesData as $ruleDataItem) {
|
foreach ($rulesData as $ruleDataItem) {
|
||||||
if(empty($ruleDataItem['ConditionOption']) || empty($ruleDataItem['Display'])) {
|
if (empty($ruleDataItem['ConditionOption']) || empty($ruleDataItem['Display'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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
|
||||||
@ -131,7 +137,7 @@ class UserFormsUpgradeService {
|
|||||||
: array();
|
: array();
|
||||||
|
|
||||||
// Skip blank rules or fields with custom rules already
|
// Skip blank rules or fields with custom rules already
|
||||||
if(empty($customSettings)) {
|
if (empty($customSettings)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,14 +156,15 @@ 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()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// If live, search stage record for matching one
|
// If live, search stage record for matching one
|
||||||
if($stage === 'Live') {
|
if ($stage === 'Live') {
|
||||||
$list = Versioned::get_by_stage('EditableCustomRule', 'Stage')
|
$list = Versioned::get_by_stage('EditableCustomRule', 'Stage')
|
||||||
->filter(array(
|
->filter(array(
|
||||||
'ParentID' => $field->ID,
|
'ParentID' => $field->ID,
|
||||||
@ -165,13 +172,13 @@ class UserFormsUpgradeService {
|
|||||||
'Display' => $display,
|
'Display' => $display,
|
||||||
'ConditionOption' => $conditionOption
|
'ConditionOption' => $conditionOption
|
||||||
));
|
));
|
||||||
if($value) {
|
if ($value) {
|
||||||
$list = $list->filter('FieldValue', $value);
|
$list = $list->filter('FieldValue', $value);
|
||||||
} else {
|
} else {
|
||||||
$list = $list->where('"FieldValue" IS NULL OR "FieldValue" = \'\'');
|
$list = $list->where('"FieldValue" IS NULL OR "FieldValue" = \'\'');
|
||||||
}
|
}
|
||||||
$rule = $list->first();
|
$rule = $list->first();
|
||||||
if($rule) {
|
if ($rule) {
|
||||||
$rule->write();
|
$rule->write();
|
||||||
$rule->publish("Stage", "Live");
|
$rule->publish("Stage", "Live");
|
||||||
return $rule;
|
return $rule;
|
||||||
@ -189,11 +196,12 @@ class UserFormsUpgradeService {
|
|||||||
return $rule;
|
return $rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function log($message) {
|
public function log($message)
|
||||||
if($this->getQuiet()) {
|
{
|
||||||
|
if ($this->getQuiet()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Director::is_cli()) {
|
if (Director::is_cli()) {
|
||||||
echo "{$message}\n";
|
echo "{$message}\n";
|
||||||
} else {
|
} else {
|
||||||
echo "{$message}<br />";
|
echo "{$message}<br />";
|
||||||
@ -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,20 +21,18 @@ 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) {
|
||||||
foreach($forms as $form) {
|
foreach ($forms as $form) {
|
||||||
echo "Publishing $form->Title <br />";
|
echo "Publishing $form->Title <br />";
|
||||||
$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,21 +119,23 @@ 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();
|
||||||
|
|
||||||
$this->assertEquals($clone->Options()->Count(), $dropdown->Options()->Count());
|
$this->assertEquals($clone->Options()->Count(), $dropdown->Options()->Count());
|
||||||
|
|
||||||
foreach($clone->Options() as $option) {
|
foreach ($clone->Options() as $option) {
|
||||||
$orginal = $dropdown->Options()->find('Title', $option->Title);
|
$orginal = $dropdown->Options()->find('Title', $option->Title);
|
||||||
|
|
||||||
$this->assertEquals($orginal->Sort, $option->Sort);
|
$this->assertEquals($orginal->Sort, $option->Sort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,14 +5,16 @@
|
|||||||
*
|
*
|
||||||
* @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')) {
|
||||||
$this->skipTest = true;
|
$this->skipTest = true;
|
||||||
$this->markTestSkipped(get_class() . ' skipped unless running with securefiles');
|
$this->markTestSkipped(get_class() . ' skipped unless running with securefiles');
|
||||||
}
|
}
|
||||||
@ -20,13 +22,15 @@ 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
|
||||||
@ -102,10 +106,11 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
|||||||
|
|
||||||
$response = $this->get($form->URLSegment.'/finished');
|
$response = $this->get($form->URLSegment.'/finished');
|
||||||
|
|
||||||
$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
|
||||||
@ -114,10 +119,11 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
|||||||
|
|
||||||
$response = $this->get($form->URLSegment.'/finished');
|
$response = $this->get($form->URLSegment.'/finished');
|
||||||
|
|
||||||
$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');
|
||||||
@ -65,7 +69,7 @@ class UserDefinedFormTest extends FunctionalTest {
|
|||||||
$this->assertTrue($fields->dataFieldByName('EmailBody') !== null);
|
$this->assertTrue($fields->dataFieldByName('EmailBody') !== null);
|
||||||
|
|
||||||
// add an email field, it should now add a or from X address picker
|
// add an email field, it should now add a or from X address picker
|
||||||
$email = $this->objFromFixture('EditableEmailField','email-field');
|
$email = $this->objFromFixture('EditableEmailField', 'email-field');
|
||||||
$form->Fields()->add($email);
|
$form->Fields()->add($email);
|
||||||
|
|
||||||
$popup->write();
|
$popup->write();
|
||||||
@ -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,11 +135,12 @@ 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');
|
||||||
foreach($form->EmailRecipients() as $recipient) {
|
foreach ($form->EmailRecipients() as $recipient) {
|
||||||
$this->assertTrue($recipient->canEdit());
|
$this->assertTrue($recipient->canEdit());
|
||||||
$this->assertTrue($recipient->canDelete());
|
$this->assertTrue($recipient->canDelete());
|
||||||
}
|
}
|
||||||
@ -141,13 +149,14 @@ class UserDefinedFormTest extends FunctionalTest {
|
|||||||
$member->logOut();
|
$member->logOut();
|
||||||
|
|
||||||
$this->logInWithPermission('SITETREE_VIEW_ALL');
|
$this->logInWithPermission('SITETREE_VIEW_ALL');
|
||||||
foreach($form->EmailRecipients() as $recipient) {
|
foreach ($form->EmailRecipients() as $recipient) {
|
||||||
$this->assertFalse($recipient->canEdit());
|
$this->assertFalse($recipient->canEdit());
|
||||||
$this->assertFalse($recipient->canDelete());
|
$this->assertFalse($recipient->canDelete());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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