diff --git a/_config.php b/_config.php
index 10cdf25..a20e677 100644
--- a/_config.php
+++ b/_config.php
@@ -1,7 +1,7 @@
value of columns from all submissions
- * @var array
- */
- protected $columns;
+ /**
+ * A map of name => value of columns from all submissions
+ * @var array
+ */
+ protected $columns;
- public function setColumns($columns) {
- $this->columns = $columns;
- }
+ public function setColumns($columns)
+ {
+ $this->columns = $columns;
+ }
- public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
- if(!$this->checkDataType($gridField->getList())) {
- return;
- }
+ public function handleAction(GridField $gridField, $actionName, $arguments, $data)
+ {
+ if (!$this->checkDataType($gridField->getList())) {
+ return;
+ }
- if($actionName === 'filter') {
- $gridField->State->UserFormsGridField = array(
- 'filter' => isset($data['FieldNameFilter']) ? $data['FieldNameFilter'] : null,
- 'value' => isset($data['FieldValue']) ? $data['FieldValue'] : null,
- 'start' => isset($data['StartFilter']) ? $data['StartFilter'] : null,
- 'end' => isset($data['EndFilter']) ? $data['EndFilter'] : null
- );
- }
- }
+ if ($actionName === 'filter') {
+ $gridField->State->UserFormsGridField = array(
+ 'filter' => isset($data['FieldNameFilter']) ? $data['FieldNameFilter'] : null,
+ 'value' => isset($data['FieldValue']) ? $data['FieldValue'] : null,
+ 'start' => isset($data['StartFilter']) ? $data['StartFilter'] : null,
+ 'end' => isset($data['EndFilter']) ? $data['EndFilter'] : null
+ );
+ }
+ }
- public function getHTMLFragments($gridField) {
- $fields = new ArrayList();
- $state = $gridField->State->UserFormsGridField;
+ public function getHTMLFragments($gridField)
+ {
+ $fields = new ArrayList();
+ $state = $gridField->State->UserFormsGridField;
- $selectedField = $state->filter;
- $selectedValue = $state->value;
+ $selectedField = $state->filter;
+ $selectedValue = $state->value;
- // show dropdown of all the fields available from the submitted form fields
- // that have been saved. Takes the titles from the currently live form.
- $columnField = new DropdownField('FieldNameFilter', '');
- $columnField->setSource($this->columns);
- $columnField->setEmptyString(_t('UserFormsGridFieldFilterHeader.FILTERSUBMISSIONS', 'Filter Submissions..'));
- $columnField->setHasEmptyDefault(true);
- $columnField->setValue($selectedField);
+ // show dropdown of all the fields available from the submitted form fields
+ // that have been saved. Takes the titles from the currently live form.
+ $columnField = new DropdownField('FieldNameFilter', '');
+ $columnField->setSource($this->columns);
+ $columnField->setEmptyString(_t('UserFormsGridFieldFilterHeader.FILTERSUBMISSIONS', 'Filter Submissions..'));
+ $columnField->setHasEmptyDefault(true);
+ $columnField->setValue($selectedField);
- $valueField = new TextField('FieldValue', '', $selectedValue);
+ $valueField = new TextField('FieldValue', '', $selectedValue);
- $columnField->addExtraClass('ss-gridfield-sort');
- $columnField->addExtraClass('no-change-track');
+ $columnField->addExtraClass('ss-gridfield-sort');
+ $columnField->addExtraClass('no-change-track');
- $valueField->addExtraClass('ss-gridfield-sort');
- $valueField->addExtraClass('no-change-track');
- $valueField->setAttribute(
- 'placeholder',
- _t('UserFormsGridFieldFilterHeader.WHEREVALUEIS', 'where value is..'
- ));
+ $valueField->addExtraClass('ss-gridfield-sort');
+ $valueField->addExtraClass('no-change-track');
+ $valueField->setAttribute(
+ 'placeholder',
+ _t('UserFormsGridFieldFilterHeader.WHEREVALUEIS', 'where value is..'
+ ));
- $fields->push(new FieldGroup(new CompositeField(
- $columnField,
- $valueField
- )));
+ $fields->push(new FieldGroup(new CompositeField(
+ $columnField,
+ $valueField
+ )));
- $fields->push(new FieldGroup(new CompositeField(
- $start = new DateField('StartFilter', _t('UserFormsGridFieldFilterHeader.FROM', 'From')),
- $end = new DateField('EndFilter', _t('UserFormsGridFieldFilterHeader.TILL', 'Till'))
- )));
+ $fields->push(new FieldGroup(new CompositeField(
+ $start = new DateField('StartFilter', _t('UserFormsGridFieldFilterHeader.FROM', 'From')),
+ $end = new DateField('EndFilter', _t('UserFormsGridFieldFilterHeader.TILL', 'Till'))
+ )));
- foreach(array($start, $end) as $date) {
- $date->setConfig('showcalendar', true);
- $date->setConfig('dateformat', 'y-mm-dd');
- $date->setConfig('datavalueformat', 'y-mm-dd');
- $date->addExtraClass('no-change-track');
- }
+ foreach (array($start, $end) as $date) {
+ $date->setConfig('showcalendar', true);
+ $date->setConfig('dateformat', 'y-mm-dd');
+ $date->setConfig('datavalueformat', 'y-mm-dd');
+ $date->addExtraClass('no-change-track');
+ }
- $end->setValue($state->end);
- $start->setValue($state->start);
+ $end->setValue($state->end);
+ $start->setValue($state->start);
- $fields->push($actions = new FieldGroup(
- GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
- ->addExtraClass('ss-gridfield-button-filter')
- ->setAttribute('title', _t('GridField.Filter', "Filter"))
- ->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField),
- GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
- ->addExtraClass('ss-gridfield-button-close')
- ->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
- ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)
- )
- );
+ $fields->push($actions = new FieldGroup(
+ GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
+ ->addExtraClass('ss-gridfield-button-filter')
+ ->setAttribute('title', _t('GridField.Filter', "Filter"))
+ ->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField),
+ GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
+ ->addExtraClass('ss-gridfield-button-close')
+ ->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
+ ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField)
+ )
+ );
- $actions->addExtraClass('filter-buttons');
- $actions->addExtraClass('no-change-track');
+ $actions->addExtraClass('filter-buttons');
+ $actions->addExtraClass('no-change-track');
- $forTemplate = new ArrayData(array(
- 'Fields' => $fields
- ));
+ $forTemplate = new ArrayData(array(
+ 'Fields' => $fields
+ ));
- return array(
- 'header' => $forTemplate->renderWith('GridFieldFilterHeader_Row')
- );
- }
+ return array(
+ 'header' => $forTemplate->renderWith('GridFieldFilterHeader_Row')
+ );
+ }
- public function getManipulatedData(GridField $gridField, SS_List $dataList) {
- $state = $gridField->State;
+ public function getManipulatedData(GridField $gridField, SS_List $dataList)
+ {
+ $state = $gridField->State;
- if($filter = $state->UserFormsGridField->toArray()) {
- if(isset($filter['filter']) && $filter['filter'] && isset($filter['value']) && $filter['value']) {
- $dataList = $dataList->where(sprintf("
+ if ($filter = $state->UserFormsGridField->toArray()) {
+ if (isset($filter['filter']) && $filter['filter'] && isset($filter['value']) && $filter['value']) {
+ $dataList = $dataList->where(sprintf("
SELECT COUNT(*) FROM SubmittedFormField
WHERE (
ParentID = SubmittedForm.ID AND
@@ -121,24 +126,24 @@ class UserFormsGridFieldFilterHeader extends GridFieldFilterHeader {
Value LIKE '%s'
) > 0",
- Convert::raw2sql($filter['filter']),
- Convert::raw2sql($filter['value'])
- ));
- }
+ Convert::raw2sql($filter['filter']),
+ Convert::raw2sql($filter['value'])
+ ));
+ }
- if(isset($filter['start']) && $filter['start']) {
- $dataList = $dataList->filter(array(
- 'Created:GreaterThan' => $filter['start']
- ));
- }
+ if (isset($filter['start']) && $filter['start']) {
+ $dataList = $dataList->filter(array(
+ 'Created:GreaterThan' => $filter['start']
+ ));
+ }
- if(isset($filter['end']) && $filter['end']) {
- $dataList = $dataList->filter(array(
- 'Created:LessThan' => $filter['end']
- ));
- }
- }
+ if (isset($filter['end']) && $filter['end']) {
+ $dataList = $dataList->filter(array(
+ 'Created:LessThan' => $filter['end']
+ ));
+ }
+ }
- return $dataList;
- }
+ return $dataList;
+ }
}
diff --git a/code/extensions/SecureEditableFileField.php b/code/extensions/SecureEditableFileField.php
index e8bae94..6a605a0 100644
--- a/code/extensions/SecureEditableFileField.php
+++ b/code/extensions/SecureEditableFileField.php
@@ -5,140 +5,147 @@
*
* {@see EditableFileField}
*/
-class SecureEditableFileField extends DataExtension {
+class SecureEditableFileField extends DataExtension
+{
- /**
- * Path to secure files location under assets
- *
- * @config
- * @var type
- */
- private static $secure_folder_name = 'SecureUploads';
+ /**
+ * Path to secure files location under assets
+ *
+ * @config
+ * @var type
+ */
+ private static $secure_folder_name = 'SecureUploads';
- /**
- * Disable file security if a user-defined mechanism is in place
- *
- * @config
- * @var bool
- */
- private static $disable_security = false;
+ /**
+ * Disable file security if a user-defined mechanism is in place
+ *
+ * @config
+ * @var bool
+ */
+ private static $disable_security = false;
- /*
- * Check if file security is enabled
- *
- * @return bool
- */
- public function getIsSecurityEnabled() {
- // Skip if requested
- if($this->owner->config()->disable_security) {
- return false;
- }
+ /*
+ * Check if file security is enabled
+ *
+ * @return bool
+ */
+ public function getIsSecurityEnabled()
+ {
+ // Skip if requested
+ if ($this->owner->config()->disable_security) {
+ return false;
+ }
- // Check for necessary security module
- if(!class_exists('SecureFileExtension')) {
- trigger_error('SecureEditableFileField requires secureassets module', E_USER_WARNING);
- return false;
- }
+ // Check for necessary security module
+ if (!class_exists('SecureFileExtension')) {
+ trigger_error('SecureEditableFileField requires secureassets module', E_USER_WARNING);
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- public function requireDefaultRecords() {
- // Skip if disabled
- if(!$this->getIsSecurityEnabled()) {
- return;
- }
+ public function requireDefaultRecords()
+ {
+ // Skip if disabled
+ if (!$this->getIsSecurityEnabled()) {
+ return;
+ }
- // Update all instances of editablefilefield which do NOT have a secure folder assigned
- foreach(EditableFileField::get() as $fileField) {
- // Skip if secured
- if($fileField->getIsSecure()) {
- continue;
- }
+ // Update all instances of editablefilefield which do NOT have a secure folder assigned
+ foreach (EditableFileField::get() as $fileField) {
+ // Skip if secured
+ if ($fileField->getIsSecure()) {
+ continue;
+ }
- // Force this field to secure itself on write
- $fileField->write(false, false, true);
- DB::alteration_message(
- "Restricting editable file field \"{$fileField->Title}\" to secure folder",
- "changed"
- );
- }
- }
+ // Force this field to secure itself on write
+ $fileField->write(false, false, true);
+ DB::alteration_message(
+ "Restricting editable file field \"{$fileField->Title}\" to secure folder",
+ "changed"
+ );
+ }
+ }
- /**
- * Secure this field before saving
- */
- public function onBeforeWrite() {
- $this->makeSecure();
- }
+ /**
+ * Secure this field before saving
+ */
+ public function onBeforeWrite()
+ {
+ $this->makeSecure();
+ }
- /**
- * Ensure this field is secured, but does not write changes to the database
- */
- public function makeSecure() {
- // Skip if disabled or already secure
- if(!$this->getIsSecurityEnabled() || $this->owner->getIsSecure()) {
- return;
- }
+ /**
+ * Ensure this field is secured, but does not write changes to the database
+ */
+ public function makeSecure()
+ {
+ // Skip if disabled or already secure
+ if (!$this->getIsSecurityEnabled() || $this->owner->getIsSecure()) {
+ return;
+ }
- // Ensure folder exists
- $folder = $this->owner->Folder();
- if(!$folder || !$folder->exists()) {
- // Create new folder in default location
- $folder = Folder::find_or_make($this->owner->config()->secure_folder_name);
- $this->owner->FolderID = $folder->ID;
+ // Ensure folder exists
+ $folder = $this->owner->Folder();
+ if (!$folder || !$folder->exists()) {
+ // Create new folder in default location
+ $folder = Folder::find_or_make($this->owner->config()->secure_folder_name);
+ $this->owner->FolderID = $folder->ID;
+ } elseif ($this->isFolderSecured($folder)) {
+ // If folder exists and is secure stop
+ return;
+ }
- } elseif($this->isFolderSecured($folder)) {
- // If folder exists and is secure stop
- return;
- }
+ // Make secure
+ $folder->CanViewType = 'OnlyTheseUsers';
+ $folder->ViewerGroups()->add($this->findAdminGroup());
+ $folder->write();
+ }
- // Make secure
- $folder->CanViewType = 'OnlyTheseUsers';
- $folder->ViewerGroups()->add($this->findAdminGroup());
- $folder->write();
- }
+ /**
+ * Find target group to record
+ *
+ * @return Group
+ */
+ protected function findAdminGroup()
+ {
+ singleton('Group')->requireDefaultRecords();
+ return Permission::get_groups_by_permission('ADMIN')->First();
+ }
- /**
- * Find target group to record
- *
- * @return Group
- */
- protected function findAdminGroup() {
- singleton('Group')->requireDefaultRecords();
- return Permission::get_groups_by_permission('ADMIN')->First();
- }
+ /**
+ * Determine if the field is secure
+ *
+ * @return bool
+ */
+ public function getIsSecure()
+ {
+ return $this->isFolderSecured($this->owner->Folder());
+ }
- /**
- * Determine if the field is secure
- *
- * @return bool
- */
- public function getIsSecure() {
- return $this->isFolderSecured($this->owner->Folder());
- }
+ /**
+ * Check if a Folder object is secure
+ *
+ * @param Folder $folder
+ * @return boolean
+ */
+ protected function isFolderSecured($folder)
+ {
+ if (! ($folder instanceof Folder) || !$folder->exists()) {
+ return false;
+ }
- /**
- * Check if a Folder object is secure
- *
- * @param Folder $folder
- * @return boolean
- */
- protected function isFolderSecured($folder) {
- if(! ($folder instanceof Folder) || !$folder->exists()) {
- return false;
- }
-
- switch($folder->CanViewType) {
- case 'OnlyTheseUsers':
- return true;
- case 'Inherit':
- $parent = $folder->Parent();
- return $parent && $parent->exists() && $this->isFolderSecured($parent);
- case 'Anyone':
- case 'LoggedInUsers':
- default:
- return false;
- }
- }
+ switch ($folder->CanViewType) {
+ case 'OnlyTheseUsers':
+ return true;
+ case 'Inherit':
+ $parent = $folder->Parent();
+ return $parent && $parent->exists() && $this->isFolderSecured($parent);
+ case 'Anyone':
+ case 'LoggedInUsers':
+ default:
+ return false;
+ }
+ }
}
diff --git a/code/extensions/UserFormFieldEditorExtension.php b/code/extensions/UserFormFieldEditorExtension.php
index 0fd1e55..248a68a 100644
--- a/code/extensions/UserFormFieldEditorExtension.php
+++ b/code/extensions/UserFormFieldEditorExtension.php
@@ -3,235 +3,245 @@
/**
* @package userforms
*/
-class UserFormFieldEditorExtension extends DataExtension {
+class UserFormFieldEditorExtension extends DataExtension
+{
- /**
- * @var array
- */
- private static $has_many = array(
- 'Fields' => 'EditableFormField'
- );
+ /**
+ * @var array
+ */
+ private static $has_many = array(
+ 'Fields' => 'EditableFormField'
+ );
- /**
- * Adds the field editor to the page.
- *
- * @return FieldList
- */
- public function updateCMSFields(FieldList $fields) {
- $fieldEditor = $this->getFieldEditorGrid();
+ /**
+ * Adds the field editor to the page.
+ *
+ * @return FieldList
+ */
+ public function updateCMSFields(FieldList $fields)
+ {
+ $fieldEditor = $this->getFieldEditorGrid();
- $fields->insertAfter(new Tab('FormFields', _t('UserFormFieldEditorExtension.FORMFIELDS', 'Form Fields')), 'Main');
- $fields->addFieldToTab('Root.FormFields', $fieldEditor);
+ $fields->insertAfter(new Tab('FormFields', _t('UserFormFieldEditorExtension.FORMFIELDS', 'Form Fields')), 'Main');
+ $fields->addFieldToTab('Root.FormFields', $fieldEditor);
- return $fields;
- }
+ return $fields;
+ }
- /**
- * Gets the field editor, for adding and removing EditableFormFields.
- *
- * @return GridField
- */
- public function getFieldEditorGrid() {
- Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
+ /**
+ * Gets the field editor, for adding and removing EditableFormFields.
+ *
+ * @return GridField
+ */
+ public function getFieldEditorGrid()
+ {
+ Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
- $fields = $this->owner->Fields();
+ $fields = $this->owner->Fields();
- $this->createInitialFormStep(true);
+ $this->createInitialFormStep(true);
- $editableColumns = new GridFieldEditableColumns();
- $fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
- $editableColumns->setDisplayFields(array(
- 'ClassName' => function($record, $column, $grid) use ($fieldClasses) {
- if($record instanceof EditableFormField) {
- return $record->getInlineClassnameField($column, $fieldClasses);
- }
- },
- 'Title' => function($record, $column, $grid) {
- if($record instanceof EditableFormField) {
- return $record->getInlineTitleField($column);
- }
- }
- ));
+ $editableColumns = new GridFieldEditableColumns();
+ $fieldClasses = singleton('EditableFormField')->getEditableFieldClasses();
+ $editableColumns->setDisplayFields(array(
+ 'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
+ if ($record instanceof EditableFormField) {
+ return $record->getInlineClassnameField($column, $fieldClasses);
+ }
+ },
+ 'Title' => function ($record, $column, $grid) {
+ if ($record instanceof EditableFormField) {
+ return $record->getInlineTitleField($column);
+ }
+ }
+ ));
- $config = GridFieldConfig::create()
- ->addComponents(
- $editableColumns,
- new GridFieldButtonRow(),
- GridFieldAddClassesButton::create('EditableTextField')
- ->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
- ->setButtonClass('ss-ui-action-constructive'),
- GridFieldAddClassesButton::create('EditableFormStep')
- ->setButtonName(_t('UserFormFieldEditorExtension.ADD_PAGE_BREAK', 'Add Page Break')),
- GridFieldAddClassesButton::create(array('EditableFieldGroup', 'EditableFieldGroupEnd'))
- ->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD_GROUP', 'Add Field Group')),
- new GridFieldEditButton(),
- new GridFieldDeleteAction(),
- new GridFieldToolbarHeader(),
- new GridFieldOrderableRows('Sort'),
- new GridFieldDetailForm()
- );
+ $config = GridFieldConfig::create()
+ ->addComponents(
+ $editableColumns,
+ new GridFieldButtonRow(),
+ GridFieldAddClassesButton::create('EditableTextField')
+ ->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD', 'Add Field'))
+ ->setButtonClass('ss-ui-action-constructive'),
+ GridFieldAddClassesButton::create('EditableFormStep')
+ ->setButtonName(_t('UserFormFieldEditorExtension.ADD_PAGE_BREAK', 'Add Page Break')),
+ GridFieldAddClassesButton::create(array('EditableFieldGroup', 'EditableFieldGroupEnd'))
+ ->setButtonName(_t('UserFormFieldEditorExtension.ADD_FIELD_GROUP', 'Add Field Group')),
+ new GridFieldEditButton(),
+ new GridFieldDeleteAction(),
+ new GridFieldToolbarHeader(),
+ new GridFieldOrderableRows('Sort'),
+ new GridFieldDetailForm()
+ );
- $fieldEditor = GridField::create(
- 'Fields',
- _t('UserDefinedForm.FIELDS', 'Fields'),
- $fields,
- $config
- )->addExtraClass('uf-field-editor');
+ $fieldEditor = GridField::create(
+ 'Fields',
+ _t('UserDefinedForm.FIELDS', 'Fields'),
+ $fields,
+ $config
+ )->addExtraClass('uf-field-editor');
- return $fieldEditor;
- }
+ return $fieldEditor;
+ }
- /**
- * A UserForm must have at least one step.
- * If no steps exist, create an initial step, and put all fields inside it.
- *
- * @param bool $force
- * @return void
- */
- public function createInitialFormStep($force = false) {
- // Only invoke once saved
- if(!$this->owner->exists()) {
- return;
- }
+ /**
+ * A UserForm must have at least one step.
+ * If no steps exist, create an initial step, and put all fields inside it.
+ *
+ * @param bool $force
+ * @return void
+ */
+ public function createInitialFormStep($force = false)
+ {
+ // Only invoke once saved
+ if (!$this->owner->exists()) {
+ return;
+ }
- // Check if first field is a step
- $fields = $this->owner->Fields();
- $firstField = $fields->first();
- if($firstField instanceof EditableFormStep) {
- return;
- }
+ // Check if first field is a step
+ $fields = $this->owner->Fields();
+ $firstField = $fields->first();
+ if ($firstField instanceof EditableFormStep) {
+ return;
+ }
- // Don't create steps on write if there are no formfields, as this
- // can create duplicate first steps during publish of new records
- if(!$force && !$firstField) {
- return;
- }
+ // Don't create steps on write if there are no formfields, as this
+ // can create duplicate first steps during publish of new records
+ if (!$force && !$firstField) {
+ return;
+ }
- // Re-apply sort to each field starting at 2
- $next = 2;
- foreach($fields as $field) {
- $field->Sort = $next++;
- $field->write();
- }
+ // Re-apply sort to each field starting at 2
+ $next = 2;
+ foreach ($fields as $field) {
+ $field->Sort = $next++;
+ $field->write();
+ }
- // Add step
- $step = EditableFormStep::create();
- $step->Title = _t('EditableFormStep.TITLE_FIRST', 'First Page');
- $step->Sort = 1;
- $step->write();
- $fields->add($step);
- }
+ // Add step
+ $step = EditableFormStep::create();
+ $step->Title = _t('EditableFormStep.TITLE_FIRST', 'First Page');
+ $step->Sort = 1;
+ $step->write();
+ $fields->add($step);
+ }
- /**
- * Ensure that at least one page exists at the start
- */
- public function onAfterWrite() {
- $this->createInitialFormStep();
- }
+ /**
+ * Ensure that at least one page exists at the start
+ */
+ public function onAfterWrite()
+ {
+ $this->createInitialFormStep();
+ }
- /**
- * @see SiteTree::doPublish
- * @param Page $original
- *
- * @return void
- */
- public function onAfterPublish($original) {
- // Remove fields on the live table which could have been orphaned.
- $live = Versioned::get_by_stage("EditableFormField", "Live")
- ->filter('ParentID', $original->ID);
+ /**
+ * @see SiteTree::doPublish
+ * @param Page $original
+ *
+ * @return void
+ */
+ public function onAfterPublish($original)
+ {
+ // Remove fields on the live table which could have been orphaned.
+ $live = Versioned::get_by_stage("EditableFormField", "Live")
+ ->filter('ParentID', $original->ID);
- if($live) {
- foreach($live as $field) {
- $field->doDeleteFromStage('Live');
- }
- }
+ if ($live) {
+ foreach ($live as $field) {
+ $field->doDeleteFromStage('Live');
+ }
+ }
- foreach($this->owner->Fields() as $field) {
- $field->doPublish('Stage', 'Live');
- }
- }
+ foreach ($this->owner->Fields() as $field) {
+ $field->doPublish('Stage', 'Live');
+ }
+ }
- /**
- * @see SiteTree::doUnpublish
- * @param Page $page
- *
- * @return void
- */
- public function onAfterUnpublish($page) {
- foreach($page->Fields() as $field) {
- $field->doDeleteFromStage('Live');
- }
- }
+ /**
+ * @see SiteTree::doUnpublish
+ * @param Page $page
+ *
+ * @return void
+ */
+ public function onAfterUnpublish($page)
+ {
+ foreach ($page->Fields() as $field) {
+ $field->doDeleteFromStage('Live');
+ }
+ }
- /**
- * @see SiteTree::duplicate
- * @param DataObject $newPage
- *
- * @return DataObject
- */
- public function onAfterDuplicate($newPage) {
- // List of EditableFieldGroups, where the
- // key of the array is the ID of the old end group
- $fieldGroups = array();
- foreach($this->owner->Fields() as $field) {
- $newField = $field->duplicate(false);
- $newField->ParentID = $newPage->ID;
- $newField->ParentClass = $newPage->ClassName;
- $newField->Version = 0;
- $newField->write();
+ /**
+ * @see SiteTree::duplicate
+ * @param DataObject $newPage
+ *
+ * @return DataObject
+ */
+ public function onAfterDuplicate($newPage)
+ {
+ // List of EditableFieldGroups, where the
+ // key of the array is the ID of the old end group
+ $fieldGroups = array();
+ foreach ($this->owner->Fields() as $field) {
+ $newField = $field->duplicate(false);
+ $newField->ParentID = $newPage->ID;
+ $newField->ParentClass = $newPage->ClassName;
+ $newField->Version = 0;
+ $newField->write();
- // If we encounter a group start, record it for later use
- if($field instanceof EditableFieldGroup) {
- $fieldGroups[$field->EndID] = $newField;
- }
+ // If we encounter a group start, record it for later use
+ if ($field instanceof EditableFieldGroup) {
+ $fieldGroups[$field->EndID] = $newField;
+ }
- // If we encounter an end group, link it back to the group start
- if($field instanceof EditableFieldGroupEnd && isset($fieldGroups[$field->ID])) {
- $groupStart = $fieldGroups[$field->ID];
- $groupStart->EndID = $newField->ID;
- $groupStart->write();
- }
+ // If we encounter an end group, link it back to the group start
+ if ($field instanceof EditableFieldGroupEnd && isset($fieldGroups[$field->ID])) {
+ $groupStart = $fieldGroups[$field->ID];
+ $groupStart->EndID = $newField->ID;
+ $groupStart->write();
+ }
- foreach ($field->DisplayRules() as $customRule) {
- $newRule = $customRule->duplicate(false);
- $newRule->ParentID = $newField->ID;
- $newRule->Version = 0;
- $newRule->write();
- }
- }
+ foreach ($field->DisplayRules() as $customRule) {
+ $newRule = $customRule->duplicate(false);
+ $newRule->ParentID = $newField->ID;
+ $newRule->Version = 0;
+ $newRule->write();
+ }
+ }
- return $newPage;
- }
+ return $newPage;
+ }
- /**
- * @see SiteTree::getIsModifiedOnStage
- * @param boolean $isModified
- *
- * @return boolean
- */
- public function getIsModifiedOnStage($isModified) {
- if(!$isModified) {
- foreach($this->owner->Fields() as $field) {
- if($field->getIsModifiedOnStage()) {
- $isModified = true;
- break;
- }
- }
- }
+ /**
+ * @see SiteTree::getIsModifiedOnStage
+ * @param boolean $isModified
+ *
+ * @return boolean
+ */
+ public function getIsModifiedOnStage($isModified)
+ {
+ if (!$isModified) {
+ foreach ($this->owner->Fields() as $field) {
+ if ($field->getIsModifiedOnStage()) {
+ $isModified = true;
+ break;
+ }
+ }
+ }
- return $isModified;
- }
+ return $isModified;
+ }
- /**
- * @see SiteTree::doRevertToLive
- * @param Page $page
- *
- * @return void
- */
- public function onAfterRevertToLive($page) {
- foreach($page->Fields() as $field) {
- $field->publish('Live', 'Stage', false);
- $field->writeWithoutVersion();
- }
- }
+ /**
+ * @see SiteTree::doRevertToLive
+ * @param Page $page
+ *
+ * @return void
+ */
+ public function onAfterRevertToLive($page)
+ {
+ foreach ($page->Fields() as $field) {
+ $field->publish('Live', 'Stage', false);
+ $field->writeWithoutVersion();
+ }
+ }
}
diff --git a/code/extensions/UserFormValidator.php b/code/extensions/UserFormValidator.php
index 72440aa..1b81fa2 100644
--- a/code/extensions/UserFormValidator.php
+++ b/code/extensions/UserFormValidator.php
@@ -1,126 +1,128 @@
filter('ParentID', $data['ID'])->sort('"Sort" ASC');
+ $fields = EditableFormField::get()->filter('ParentID', $data['ID'])->sort('"Sort" ASC');
- // Current nesting
- $stack = array();
- $conditionalStep = false; // Is the current step conditional?
- foreach($fields as $field) {
- if($field instanceof EditableFormStep) {
- // Page at top level, or after another page is ok
- if(empty($stack) || (count($stack) === 1 && $stack[0] instanceof EditableFormStep)) {
- $stack = array($field);
- $conditionalStep = $field->EffectiveDisplayRules()->count() > 0;
- continue;
- }
+ // Current nesting
+ $stack = array();
+ $conditionalStep = false; // Is the current step conditional?
+ foreach ($fields as $field) {
+ if ($field instanceof EditableFormStep) {
+ // Page at top level, or after another page is ok
+ if (empty($stack) || (count($stack) === 1 && $stack[0] instanceof EditableFormStep)) {
+ $stack = array($field);
+ $conditionalStep = $field->EffectiveDisplayRules()->count() > 0;
+ continue;
+ }
- $this->validationError(
- 'FormFields',
- _t(
- "UserFormValidator.UNEXPECTED_BREAK",
- "Unexpected page break '{name}' inside nested field '{group}'",
- array(
- 'name' => $field->CMSTitle,
- 'group' => end($stack)->CMSTitle
- )
- ),
- 'error'
- );
- return false;
- }
+ $this->validationError(
+ 'FormFields',
+ _t(
+ "UserFormValidator.UNEXPECTED_BREAK",
+ "Unexpected page break '{name}' inside nested field '{group}'",
+ array(
+ 'name' => $field->CMSTitle,
+ 'group' => end($stack)->CMSTitle
+ )
+ ),
+ 'error'
+ );
+ return false;
+ }
- // Validate no pages
- if(empty($stack)) {
- $this->validationError(
- 'FormFields',
- _t(
- "UserFormValidator.NO_PAGE",
- "Field '{name}' found before any pages",
- array(
- 'name' => $field->CMSTitle
- )
- ),
- 'error'
- );
- return false;
- }
+ // Validate no pages
+ if (empty($stack)) {
+ $this->validationError(
+ 'FormFields',
+ _t(
+ "UserFormValidator.NO_PAGE",
+ "Field '{name}' found before any pages",
+ array(
+ 'name' => $field->CMSTitle
+ )
+ ),
+ 'error'
+ );
+ return false;
+ }
- // Nest field group
- if($field instanceof EditableFieldGroup) {
- $stack[] = $field;
- continue;
- }
+ // Nest field group
+ if ($field instanceof EditableFieldGroup) {
+ $stack[] = $field;
+ continue;
+ }
- // Unnest field group
- if($field instanceof EditableFieldGroupEnd) {
- $top = end($stack);
+ // Unnest field group
+ if ($field instanceof EditableFieldGroupEnd) {
+ $top = end($stack);
- // Check that the top is a group at all
- if(!$top instanceof EditableFieldGroup) {
- $this->validationError(
- 'FormFields',
- _t(
- "UserFormValidator.UNEXPECTED_GROUP_END",
- "'{name}' found without a matching group",
- array(
- 'name' => $field->CMSTitle
- )
- ),
- 'error'
- );
- return false;
- }
+ // Check that the top is a group at all
+ if (!$top instanceof EditableFieldGroup) {
+ $this->validationError(
+ 'FormFields',
+ _t(
+ "UserFormValidator.UNEXPECTED_GROUP_END",
+ "'{name}' found without a matching group",
+ array(
+ 'name' => $field->CMSTitle
+ )
+ ),
+ 'error'
+ );
+ return false;
+ }
- // Check that the top is the right group
- if($top->EndID != $field->ID) {
- $this->validationError(
- 'FormFields',
- _t(
- "UserFormValidator.WRONG_GROUP_END",
- "'{name}' found closes the wrong group '{group}'",
- array(
- 'name' => $field->CMSTitle,
- 'group' => $top->CMSTitle
- )
- ),
- 'error'
- );
- return false;
- }
+ // Check that the top is the right group
+ if ($top->EndID != $field->ID) {
+ $this->validationError(
+ 'FormFields',
+ _t(
+ "UserFormValidator.WRONG_GROUP_END",
+ "'{name}' found closes the wrong group '{group}'",
+ array(
+ 'name' => $field->CMSTitle,
+ 'group' => $top->CMSTitle
+ )
+ ),
+ 'error'
+ );
+ return false;
+ }
- // Unnest group
- array_pop($stack);
- }
+ // Unnest group
+ array_pop($stack);
+ }
- // Normal field type
- if($conditionalStep && $field->Required) {
- $this->validationError(
- 'FormFields',
- _t(
- "UserFormValidator.CONDITIONAL_REQUIRED",
- "Required field '{name}' cannot be placed within a conditional page",
- array(
- 'name' => $field->CMSTitle
- )
- ),
- 'error'
- );
- return false;
- }
- }
+ // Normal field type
+ if ($conditionalStep && $field->Required) {
+ $this->validationError(
+ 'FormFields',
+ _t(
+ "UserFormValidator.CONDITIONAL_REQUIRED",
+ "Required field '{name}' cannot be placed within a conditional page",
+ array(
+ 'name' => $field->CMSTitle
+ )
+ ),
+ 'error'
+ );
+ return false;
+ }
+ }
- return true;
- }
+ return true;
+ }
}
diff --git a/code/formfields/UserFormsCheckboxSetField.php b/code/formfields/UserFormsCheckboxSetField.php
index 1fd5954..32ccb9b 100644
--- a/code/formfields/UserFormsCheckboxSetField.php
+++ b/code/formfields/UserFormsCheckboxSetField.php
@@ -3,63 +3,65 @@
/**
* @package userforms
*/
-class UserFormsCheckboxSetField extends CheckboxSetField {
+class UserFormsCheckboxSetField extends CheckboxSetField
+{
- /**
- * jQuery validate requires that the value of the option does not contain
- * the actual value of the input.
- *
- * @return ArrayList
- */
- public function getOptions() {
- $options = parent::getOptions();
+ /**
+ * jQuery validate requires that the value of the option does not contain
+ * the actual value of the input.
+ *
+ * @return ArrayList
+ */
+ public function getOptions()
+ {
+ $options = parent::getOptions();
- foreach($options as $option) {
- $option->Name = "{$this->name}[]";
- }
+ foreach ($options as $option) {
+ $option->Name = "{$this->name}[]";
+ }
- return $options;
- }
+ return $options;
+ }
- /**
- * @inheritdoc
- *
- * @return array
- */
- public function getSourceAsArray()
- {
- $array = parent::getSourceAsArray();
+ /**
+ * @inheritdoc
+ *
+ * @return array
+ */
+ public function getSourceAsArray()
+ {
+ $array = parent::getSourceAsArray();
- return array_values($array);
- }
+ return array_values($array);
+ }
- /**
- * @inheritdoc
- *
- * @param Validator $validator
- *
- * @return bool
- */
- public function validate($validator)
- {
- // get the previous values (could contain comma-delimited list)
+ /**
+ * @inheritdoc
+ *
+ * @param Validator $validator
+ *
+ * @return bool
+ */
+ public function validate($validator)
+ {
+ // get the previous values (could contain comma-delimited list)
- $previous = $value = $this->Value();
+ $previous = $value = $this->Value();
- if (is_string($value) && strstr($value, ",")) {
- $value = explode(",", $value);
- }
+ if (is_string($value) && strstr($value, ",")) {
+ $value = explode(",", $value);
+ }
- // set the value as an array for parent validation
+ // set the value as an array for parent validation
- $this->setValue($value);
+ $this->setValue($value);
- $validated = parent::validate($validator);
+ $validated = parent::validate($validator);
- // restore previous value after validation
+ // restore previous value after validation
- $this->setValue($previous);
+ $this->setValue($previous);
- return $validated;
- }
+ return $validated;
+ }
}
diff --git a/code/formfields/UserFormsCompositeField.php b/code/formfields/UserFormsCompositeField.php
index 5188b54..17f2476 100644
--- a/code/formfields/UserFormsCompositeField.php
+++ b/code/formfields/UserFormsCompositeField.php
@@ -3,45 +3,49 @@
/**
* 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
- *
- * @var UserFormsFieldContainer
- */
- protected $parent = null;
+ /**
+ * Parent field
+ *
+ * @var UserFormsFieldContainer
+ */
+ protected $parent = null;
- public function getParent() {
- return $this->parent;
- }
+ public function getParent()
+ {
+ return $this->parent;
+ }
- public function setParent(UserFormsFieldContainer $parent) {
- $this->parent = $parent;
- return $this;
- }
+ public function setParent(UserFormsFieldContainer $parent)
+ {
+ $this->parent = $parent;
+ return $this;
+ }
- public function processNext(EditableFormField $field) {
- // When we find a step, bubble up to the top
- if($field instanceof EditableFormStep) {
- return $this->getParent()->processNext($field);
- }
+ public function processNext(EditableFormField $field)
+ {
+ // When we find a step, bubble up to the top
+ if ($field instanceof EditableFormStep) {
+ return $this->getParent()->processNext($field);
+ }
- // Skip over fields that don't generate formfields
- $formField = $field->getFormField();
- if(!$formField) {
- return $this;
- }
+ // Skip over fields that don't generate formfields
+ $formField = $field->getFormField();
+ if (!$formField) {
+ return $this;
+ }
- // Save this field
- $this->push($formField);
+ // Save this field
+ $this->push($formField);
- // Nest fields that are containers
- if($formField instanceof UserFormsFieldContainer) {
- return $formField->setParent($this);
- }
+ // Nest fields that are containers
+ if ($formField instanceof UserFormsFieldContainer) {
+ return $formField->setParent($this);
+ }
- // Add any subsequent fields to this
- return $this;
- }
+ // Add any subsequent fields to this
+ return $this;
+ }
}
diff --git a/code/formfields/UserFormsFieldContainer.php b/code/formfields/UserFormsFieldContainer.php
index b43f7b0..2186a41 100644
--- a/code/formfields/UserFormsFieldContainer.php
+++ b/code/formfields/UserFormsFieldContainer.php
@@ -3,28 +3,29 @@
/**
* 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.
- *
- * @param EditableFormField $field
- * @return EditableContainerField
- */
- public function processNext(EditableFormField $field);
+ /**
+ * Process the next field in the list, returning the container to add the next field to.
+ *
+ * @param EditableFormField $field
+ * @return EditableContainerField
+ */
+ public function processNext(EditableFormField $field);
- /**
- * Set the parent
- *
- * @param UserFormsFieldContainer $parent
- * @return $this
- */
- public function setParent(UserFormsFieldContainer $parent);
+ /**
+ * Set the parent
+ *
+ * @param UserFormsFieldContainer $parent
+ * @return $this
+ */
+ public function setParent(UserFormsFieldContainer $parent);
- /**
- * Get the parent
- *
- * @return UserFormsFieldContainer
- */
- public function getParent();
+ /**
+ * Get the parent
+ *
+ * @return UserFormsFieldContainer
+ */
+ public function getParent();
}
diff --git a/code/formfields/UserFormsFieldList.php b/code/formfields/UserFormsFieldList.php
index f01a3f6..06f17ea 100644
--- a/code/formfields/UserFormsFieldList.php
+++ b/code/formfields/UserFormsFieldList.php
@@ -3,41 +3,45 @@
/**
* 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) {
- $formField = $field->getFormField();
- if(!$formField) {
- return $this;
- }
+ public function processNext(EditableFormField $field)
+ {
+ $formField = $field->getFormField();
+ if (!$formField) {
+ return $this;
+ }
- $this->push($formField);
+ $this->push($formField);
- if($formField instanceof UserFormsFieldContainer) {
- return $formField->setParent($this);
- }
+ if ($formField instanceof UserFormsFieldContainer) {
+ return $formField->setParent($this);
+ }
- return $this;
- }
+ return $this;
+ }
- public function getParent() {
- // Field list does not have a parent
- return null;
- }
+ public function getParent()
+ {
+ // Field list does not have a parent
+ return null;
+ }
- public function setParent(UserFormsFieldContainer $parent) {
- return $this;
- }
-
- /**
- * Remove all empty steps
- */
- public function clearEmptySteps() {
- foreach($this as $field) {
- if($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
- $this->remove($field);
- }
- }
- }
+ public function setParent(UserFormsFieldContainer $parent)
+ {
+ return $this;
+ }
+ /**
+ * Remove all empty steps
+ */
+ public function clearEmptySteps()
+ {
+ foreach ($this as $field) {
+ if ($field instanceof UserFormsStepField && count($field->getChildren()) === 0) {
+ $this->remove($field);
+ }
+ }
+ }
}
diff --git a/code/formfields/UserFormsGroupField.php b/code/formfields/UserFormsGroupField.php
index a9ee733..4a0da22 100644
--- a/code/formfields/UserFormsGroupField.php
+++ b/code/formfields/UserFormsGroupField.php
@@ -3,25 +3,29 @@
/**
* Front end composite field for userforms
*/
-class UserFormsGroupField extends UserFormsCompositeField {
+class UserFormsGroupField extends UserFormsCompositeField
+{
- public function __construct($children = null) {
- parent::__construct($children);
- $this->setTag('fieldset');
- }
+ public function __construct($children = null)
+ {
+ parent::__construct($children);
+ $this->setTag('fieldset');
+ }
- public function getLegend() {
- // Legend defaults to title
- return parent::getLegend() ?: $this->Title();
- }
+ public function getLegend()
+ {
+ // Legend defaults to title
+ return parent::getLegend() ?: $this->Title();
+ }
- public function processNext(EditableFormField $field) {
- // When ending a group, jump up one level
- if($field instanceof EditableFieldGroupEnd) {
- return $this->getParent();
- }
+ public function processNext(EditableFormField $field)
+ {
+ // When ending a group, jump up one level
+ if ($field instanceof EditableFieldGroupEnd) {
+ return $this->getParent();
+ }
- // Otherwise behave as per normal composite field
- return parent::processNext($field);
- }
+ // Otherwise behave as per normal composite field
+ return parent::processNext($field);
+ }
}
diff --git a/code/formfields/UserFormsStepField.php b/code/formfields/UserFormsStepField.php
index 8cddc6f..ae9fb99 100644
--- a/code/formfields/UserFormsStepField.php
+++ b/code/formfields/UserFormsStepField.php
@@ -3,42 +3,46 @@
/**
* Represents a page step in a form, which may contain form fields or other groups
*/
-class UserFormsStepField extends UserFormsCompositeField {
+class UserFormsStepField extends UserFormsCompositeField
+{
- private static $casting = array(
- 'StepNumber' => 'Int'
- );
+ private static $casting = array(
+ 'StepNumber' => 'Int'
+ );
- /**
- * Numeric index (1 based) of this step
- *
- * Null if unassigned
- *
- * @var int|null
- */
- protected $number = null;
+ /**
+ * Numeric index (1 based) of this step
+ *
+ * Null if unassigned
+ *
+ * @var int|null
+ */
+ protected $number = null;
- public function FieldHolder($properties = array()) {
- return $this->Field($properties);
- }
+ public function FieldHolder($properties = array())
+ {
+ return $this->Field($properties);
+ }
- /**
- * Get the step number
- *
- * @return int|null
- */
- public function getStepNumber() {
- return $this->number;
- }
+ /**
+ * Get the step number
+ *
+ * @return int|null
+ */
+ public function getStepNumber()
+ {
+ return $this->number;
+ }
- /**
- * Re-assign this step to another number
- *
- * @param type $number
- * @return $this
- */
- public function setStepNumber($number) {
- $this->number = $number;
- return $this;
- }
+ /**
+ * Re-assign this step to another number
+ *
+ * @param type $number
+ * @return $this
+ */
+ public function setStepNumber($number)
+ {
+ $this->number = $number;
+ return $this;
+ }
}
diff --git a/code/formfields/UserformsTreeDropdownField.php b/code/formfields/UserformsTreeDropdownField.php
index c606b25..0494214 100644
--- a/code/formfields/UserformsTreeDropdownField.php
+++ b/code/formfields/UserformsTreeDropdownField.php
@@ -7,11 +7,13 @@
* @deprecated since version 4.0
* @package userforms
*/
-class UserformsTreeDropdownField extends TreeDropdownField {
+class UserformsTreeDropdownField extends TreeDropdownField
+{
- public function __construct($name, $title = null, $sourceObject = 'Group', $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true) {
- parent::__construct($name, $title, $sourceObject, $keyField, $labelField, $showSearch);
+ public function __construct($name, $title = null, $sourceObject = 'Group', $keyField = 'ID', $labelField = 'TreeTitle', $showSearch = true)
+ {
+ parent::__construct($name, $title, $sourceObject, $keyField, $labelField, $showSearch);
- Deprecation::notice('4.0', __CLASS__ . " is deprecated");
- }
-}
\ No newline at end of file
+ Deprecation::notice('4.0', __CLASS__ . " is deprecated");
+ }
+}
diff --git a/code/forms/GridFieldAddClassesButton.php b/code/forms/GridFieldAddClassesButton.php
index c80e19e..71431f5 100644
--- a/code/forms/GridFieldAddClassesButton.php
+++ b/code/forms/GridFieldAddClassesButton.php
@@ -3,230 +3,246 @@
/**
* 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
- *
- * @var string
- */
- protected $targetFragment;
+ /**
+ * Name of fragment to insert into
+ *
+ * @var string
+ */
+ protected $targetFragment;
- /**
- * Button title
- *
- * @var string
- */
- protected $buttonName;
+ /**
+ * Button title
+ *
+ * @var string
+ */
+ protected $buttonName;
- /**
- * Additonal CSS classes for the button
- *
- * @var string
- */
- protected $buttonClass = null;
+ /**
+ * Additonal CSS classes for the button
+ *
+ * @var string
+ */
+ protected $buttonClass = null;
- /**
- * Class names
- *
- * @var array
- */
- protected $modelClasses = null;
+ /**
+ * Class names
+ *
+ * @var array
+ */
+ protected $modelClasses = null;
- /**
- * @param array $classes Class or list of classes to create.
- * If you enter more than one class, each click of the "add" button will create one of each
- * @param string $targetFragment The fragment to render the button into
- */
- public function __construct($classes, $targetFragment = 'buttons-before-left') {
- parent::__construct();
- $this->setClasses($classes);
- $this->setFragment($targetFragment);
- }
+ /**
+ * @param array $classes Class or list of classes to create.
+ * If you enter more than one class, each click of the "add" button will create one of each
+ * @param string $targetFragment The fragment to render the button into
+ */
+ public function __construct($classes, $targetFragment = 'buttons-before-left')
+ {
+ parent::__construct();
+ $this->setClasses($classes);
+ $this->setFragment($targetFragment);
+ }
- /**
- * Change the button name
- *
- * @param string $name
- * @return $this
- */
- public function setButtonName($name) {
- $this->buttonName = $name;
- return $this;
- }
+ /**
+ * Change the button name
+ *
+ * @param string $name
+ * @return $this
+ */
+ public function setButtonName($name)
+ {
+ $this->buttonName = $name;
+ return $this;
+ }
- /**
- * Get the button name
- *
- * @return string
- */
- public function getButtonName() {
- return $this->buttonName;
- }
+ /**
+ * Get the button name
+ *
+ * @return string
+ */
+ public function getButtonName()
+ {
+ return $this->buttonName;
+ }
- /**
- * Gets the fragment name this button is rendered into.
- *
- * @return string
- */
- public function getFragment() {
- return $this->targetFragment;
- }
+ /**
+ * Gets the fragment name this button is rendered into.
+ *
+ * @return string
+ */
+ public function getFragment()
+ {
+ return $this->targetFragment;
+ }
- /**
- * Sets the fragment name this button is rendered into.
- *
- * @param string $fragment
- * @return GridFieldAddNewInlineButton $this
- */
- public function setFragment($fragment) {
- $this->targetFragment = $fragment;
- return $this;
- }
+ /**
+ * Sets the fragment name this button is rendered into.
+ *
+ * @param string $fragment
+ * @return GridFieldAddNewInlineButton $this
+ */
+ public function setFragment($fragment)
+ {
+ $this->targetFragment = $fragment;
+ return $this;
+ }
- /**
- * Get extra button class
- *
- * @return string
- */
- public function getButtonClass() {
- return $this->buttonClass;
- }
+ /**
+ * Get extra button class
+ *
+ * @return string
+ */
+ public function getButtonClass()
+ {
+ return $this->buttonClass;
+ }
- /**
- * Sets extra CSS classes for this button
- *
- * @param string $buttonClass
- * @return $this
- */
- public function setButtonClass($buttonClass) {
- $this->buttonClass = $buttonClass;
- return $this;
- }
+ /**
+ * Sets extra CSS classes for this button
+ *
+ * @param string $buttonClass
+ * @return $this
+ */
+ public function setButtonClass($buttonClass)
+ {
+ $this->buttonClass = $buttonClass;
+ return $this;
+ }
- /**
- * Get the classes of the objects to create
- *
- * @return array
- */
- public function getClasses() {
- return $this->modelClasses;
- }
+ /**
+ * Get the classes of the objects to create
+ *
+ * @return array
+ */
+ public function getClasses()
+ {
+ return $this->modelClasses;
+ }
- /**
- * Gets the list of classes which can be created, with checks for permissions.
- * Will fallback to the default model class for the given DataGrid
- *
- * @param DataGrid $grid
- * @return array
- */
- public function getClassesCreate($grid) {
- // Get explicit or fallback class list
- $classes = $this->getClasses();
- if(empty($classes) && $grid) {
- $classes = array($grid->getModelClass());
- }
+ /**
+ * Gets the list of classes which can be created, with checks for permissions.
+ * Will fallback to the default model class for the given DataGrid
+ *
+ * @param DataGrid $grid
+ * @return array
+ */
+ public function getClassesCreate($grid)
+ {
+ // Get explicit or fallback class list
+ $classes = $this->getClasses();
+ if (empty($classes) && $grid) {
+ $classes = array($grid->getModelClass());
+ }
- // Filter out classes without permission
- return array_filter($classes, function($class) {
- return singleton($class)->canCreate();
- });
- }
+ // Filter out classes without permission
+ return array_filter($classes, function ($class) {
+ return singleton($class)->canCreate();
+ });
+ }
- /**
- * Specify the classes to create
- *
- * @param array $classes
- */
- public function setClasses($classes) {
- if(!is_array($classes)) {
- $classes = $classes ? array($classes) : array();
- }
- $this->modelClasses = $classes;
- }
+ /**
+ * Specify the classes to create
+ *
+ * @param array $classes
+ */
+ public function setClasses($classes)
+ {
+ if (!is_array($classes)) {
+ $classes = $classes ? array($classes) : array();
+ }
+ $this->modelClasses = $classes;
+ }
- public function getHTMLFragments($grid) {
- // Check create permission
- $singleton = singleton($grid->getModelClass());
- if(!$singleton->canCreate()) {
- return array();
- }
+ public function getHTMLFragments($grid)
+ {
+ // Check create permission
+ $singleton = singleton($grid->getModelClass());
+ if (!$singleton->canCreate()) {
+ return array();
+ }
- // Get button name
- $buttonName = $this->getButtonName();
- if(!$buttonName) {
- // provide a default button name, can be changed by calling {@link setButtonName()} on this component
- $objectName = $singleton->i18n_singular_name();
- $buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
- }
+ // Get button name
+ $buttonName = $this->getButtonName();
+ if (!$buttonName) {
+ // provide a default button name, can be changed by calling {@link setButtonName()} on this component
+ $objectName = $singleton->i18n_singular_name();
+ $buttonName = _t('GridField.Add', 'Add {name}', array('name' => $objectName));
+ }
- $addAction = new GridField_FormAction(
- $grid,
- $this->getAction(),
- $buttonName,
- $this->getAction(),
- array()
- );
- $addAction->setAttribute('data-icon', 'add');
+ $addAction = new GridField_FormAction(
+ $grid,
+ $this->getAction(),
+ $buttonName,
+ $this->getAction(),
+ array()
+ );
+ $addAction->setAttribute('data-icon', 'add');
- if($this->getButtonClass()) {
- $addAction->addExtraClass($this->getButtonClass());
- }
+ if ($this->getButtonClass()) {
+ $addAction->addExtraClass($this->getButtonClass());
+ }
- return array(
- $this->targetFragment => $addAction->forTemplate()
- );
- }
+ return array(
+ $this->targetFragment => $addAction->forTemplate()
+ );
+ }
- /**
- * {@inheritDoc}
- */
- public function getActions($gridField) {
- return array(
- $this->getAction()
- );
- }
+ /**
+ * {@inheritDoc}
+ */
+ public function getActions($gridField)
+ {
+ return array(
+ $this->getAction()
+ );
+ }
- /**
- * Get the action suburl for this component
- *
- * @return string
- */
- protected function getAction() {
- return 'add-classes-' . strtolower(implode('-', $this->getClasses()));
- }
+ /**
+ * Get the action suburl for this component
+ *
+ * @return string
+ */
+ protected function getAction()
+ {
+ return 'add-classes-' . strtolower(implode('-', $this->getClasses()));
+ }
- public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
- switch(strtolower($actionName)) {
- case $this->getAction():
- return $this->handleAdd($gridField);
- default:
- return null;
- }
- }
+ public function handleAction(GridField $gridField, $actionName, $arguments, $data)
+ {
+ switch (strtolower($actionName)) {
+ case $this->getAction():
+ return $this->handleAdd($gridField);
+ default:
+ return null;
+ }
+ }
- /**
- * Handles adding a new instance of a selected class.
- *
- * @param GridField $grid
- * @return null
- */
- public function handleAdd($grid) {
- $classes = $this->getClassesCreate($grid);
- if(empty($classes)) {
- throw new SS_HTTPResponse_Exception(400);
- }
+ /**
+ * Handles adding a new instance of a selected class.
+ *
+ * @param GridField $grid
+ * @return null
+ */
+ public function handleAdd($grid)
+ {
+ $classes = $this->getClassesCreate($grid);
+ if (empty($classes)) {
+ throw new SS_HTTPResponse_Exception(400);
+ }
- // Add item to gridfield
- $list = $grid->getList();
- foreach($classes as $class) {
- $item = $class::create();
- $item->write();
- $list->add($item);
- }
+ // Add item to gridfield
+ $list = $grid->getList();
+ foreach ($classes as $class) {
+ $item = $class::create();
+ $item->write();
+ $list->add($item);
+ }
- // Should trigger a simple reload
- return null;
- }
+ // Should trigger a simple reload
+ return null;
+ }
}
diff --git a/code/forms/UserForm.php b/code/forms/UserForm.php
index c13ea0e..d2f1433 100644
--- a/code/forms/UserForm.php
+++ b/code/forms/UserForm.php
@@ -3,167 +3,175 @@
/**
* @package userforms
*/
-class UserForm extends Form {
+class UserForm extends Form
+{
- /**
- * @param Controller $controller
- * @param string $name
- */
- public function __construct(Controller $controller, $name = 'Form') {
+ /**
+ * @param Controller $controller
+ * @param string $name
+ */
+ public function __construct(Controller $controller, $name = 'Form')
+ {
+ $this->controller = $controller;
+ $this->setRedirectToFormOnValidationError(true);
- $this->controller = $controller;
- $this->setRedirectToFormOnValidationError(true);
+ parent::__construct(
+ $controller,
+ $name,
+ new FieldList(),
+ new FieldList()
+ );
- parent::__construct(
- $controller,
- $name,
- new FieldList(),
- new FieldList()
- );
+ $this->setFields($fields = $this->getFormFields());
+ $fields->setForm($this);
+ $this->setActions($actions = $this->getFormActions());
+ $actions->setForm($this);
+ $this->setValidator($this->getRequiredFields());
- $this->setFields($fields = $this->getFormFields());
- $fields->setForm($this);
- $this->setActions($actions = $this->getFormActions());
- $actions->setForm($this);
- $this->setValidator($this->getRequiredFields());
+ // This needs to be re-evaluated since fields have been assigned
+ $this->setupFormErrors();
- // This needs to be re-evaluated since fields have been assigned
- $this->setupFormErrors();
+ // Number each page
+ $stepNumber = 1;
+ foreach ($this->getSteps() as $step) {
+ $step->setStepNumber($stepNumber++);
+ }
- // Number each page
- $stepNumber = 1;
- foreach($this->getSteps() as $step) {
- $step->setStepNumber($stepNumber++);
- }
+ if ($controller->DisableCsrfSecurityToken) {
+ $this->disableSecurityToken();
+ }
- if($controller->DisableCsrfSecurityToken) {
- $this->disableSecurityToken();
- }
+ $data = Session::get("FormInfo.{$this->FormName()}.data");
- $data = Session::get("FormInfo.{$this->FormName()}.data");
+ if (is_array($data)) {
+ $this->loadDataFrom($data);
+ }
- if(is_array($data)) {
- $this->loadDataFrom($data);
- }
+ $this->extend('updateForm');
+ }
- $this->extend('updateForm');
- }
+ public function setupFormErrors()
+ {
+ // Suppress setupFormErrors if fields haven't been bootstrapped
+ if ($this->fields && $this->fields->exists()) {
+ return parent::setupFormErrors();
+ }
- public function setupFormErrors()
- {
- // Suppress setupFormErrors if fields haven't been bootstrapped
- if($this->fields && $this->fields->exists()) {
- return parent::setupFormErrors();
- }
+ return $this;
+ }
- return $this;
- }
+ /**
+ * Used for partial caching in the template.
+ *
+ * @return string
+ */
+ public function getLastEdited()
+ {
+ return $this->controller->LastEdited;
+ }
- /**
- * Used for partial caching in the template.
- *
- * @return string
- */
- public function getLastEdited() {
- return $this->controller->LastEdited;
- }
+ /**
+ * @return bool
+ */
+ public function getDisplayErrorMessagesAtTop()
+ {
+ return (bool)$this->controller->DisplayErrorMessagesAtTop;
+ }
- /**
- * @return bool
- */
- public function getDisplayErrorMessagesAtTop() {
- return (bool)$this->controller->DisplayErrorMessagesAtTop;
- }
+ /**
+ * Return the fieldlist, filtered to only contain steps
+ *
+ * @return ArrayList
+ */
+ public function getSteps()
+ {
+ return $this->Fields()->filterByCallback(function ($field) {
+ return $field instanceof UserFormsStepField;
+ });
+ }
- /**
- * Return the fieldlist, filtered to only contain steps
- *
- * @return ArrayList
- */
- public function getSteps() {
- return $this->Fields()->filterByCallback(function($field) {
- return $field instanceof UserFormsStepField;
- });
- }
+ /**
+ * Get the form fields for the form on this page. Can modify this FieldSet
+ * by using {@link updateFormFields()} on an {@link Extension} subclass which
+ * is applied to this controller.
+ *
+ * This will be a list of top level composite steps
+ *
+ * @return FieldList
+ */
+ public function getFormFields()
+ {
+ $fields = new UserFormsFieldList();
+ $target = $fields;
+ foreach ($this->controller->Fields() as $field) {
+ $target = $target->processNext($field);
+ }
+ $fields->clearEmptySteps();
+ $this->extend('updateFormFields', $fields);
+ $fields->setForm($this);
+ return $fields;
+ }
- /**
- * Get the form fields for the form on this page. Can modify this FieldSet
- * by using {@link updateFormFields()} on an {@link Extension} subclass which
- * is applied to this controller.
- *
- * This will be a list of top level composite steps
- *
- * @return FieldList
- */
- public function getFormFields() {
- $fields = new UserFormsFieldList();
- $target = $fields;
- foreach ($this->controller->Fields() as $field) {
- $target = $target->processNext($field);
- }
- $fields->clearEmptySteps();
- $this->extend('updateFormFields', $fields);
- $fields->setForm($this);
- return $fields;
- }
+ /**
+ * Generate the form actions for the UserDefinedForm. You
+ * can manipulate these by using {@link updateFormActions()} on
+ * a decorator.
+ *
+ * @todo Make form actions editable via their own field editor.
+ *
+ * @return FieldList
+ */
+ public function getFormActions()
+ {
+ $submitText = ($this->controller->SubmitButtonText) ? $this->controller->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
+ $clearText = ($this->controller->ClearButtonText) ? $this->controller->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
- /**
- * Generate the form actions for the UserDefinedForm. You
- * can manipulate these by using {@link updateFormActions()} on
- * a decorator.
- *
- * @todo Make form actions editable via their own field editor.
- *
- * @return FieldList
- */
- public function getFormActions() {
- $submitText = ($this->controller->SubmitButtonText) ? $this->controller->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
- $clearText = ($this->controller->ClearButtonText) ? $this->controller->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
+ $actions = new FieldList(
+ new FormAction("process", $submitText)
+ );
- $actions = new FieldList(
- new FormAction("process", $submitText)
- );
+ if ($this->controller->ShowClearButton) {
+ $actions->push(new ResetFormAction("clearForm", $clearText));
+ }
- if($this->controller->ShowClearButton) {
- $actions->push(new ResetFormAction("clearForm", $clearText));
- }
+ $this->extend('updateFormActions', $actions);
+ $actions->setForm($this);
+ return $actions;
+ }
- $this->extend('updateFormActions', $actions);
- $actions->setForm($this);
- return $actions;
- }
+ /**
+ * Get the required form fields for this form.
+ *
+ * @return RequiredFields
+ */
+ public function getRequiredFields()
+ {
+ // Generate required field validator
+ $requiredNames = $this
+ ->getController()
+ ->Fields()
+ ->filter('Required', true)
+ ->column('Name');
+ $required = new RequiredFields($requiredNames);
+ $this->extend('updateRequiredFields', $required);
+ $required->setForm($this);
+ return $required;
+ }
- /**
- * Get the required form fields for this form.
- *
- * @return RequiredFields
- */
- public function getRequiredFields() {
- // Generate required field validator
- $requiredNames = $this
- ->getController()
- ->Fields()
- ->filter('Required', true)
- ->column('Name');
- $required = new RequiredFields($requiredNames);
- $this->extend('updateRequiredFields', $required);
- $required->setForm($this);
- return $required;
- }
+ /**
+ * Override some we can add UserForm specific attributes to the form.
+ *
+ * @return array
+ */
+ public function getAttributes()
+ {
+ $attrs = parent::getAttributes();
- /**
- * Override some we can add UserForm specific attributes to the form.
- *
- * @return array
- */
- public function getAttributes() {
- $attrs = parent::getAttributes();
+ $attrs['class'] = $attrs['class'] . ' userform';
+ $attrs['data-livevalidation'] = (bool)$this->controller->EnableLiveValidation;
+ $attrs['data-toperrors'] = (bool)$this->controller->DisplayErrorMessagesAtTop;
+ $attrs['data-hidefieldlabels'] = (bool)$this->controller->HideFieldLabels;
- $attrs['class'] = $attrs['class'] . ' userform';
- $attrs['data-livevalidation'] = (bool)$this->controller->EnableLiveValidation;
- $attrs['data-toperrors'] = (bool)$this->controller->DisplayErrorMessagesAtTop;
- $attrs['data-hidefieldlabels'] = (bool)$this->controller->HideFieldLabels;
-
- return $attrs;
- }
+ return $attrs;
+ }
}
diff --git a/code/model/EditableCustomRule.php b/code/model/EditableCustomRule.php
index df2e8ee..8ee1a3a 100644
--- a/code/model/EditableCustomRule.php
+++ b/code/model/EditableCustomRule.php
@@ -7,100 +7,107 @@
* @method EditableFormField Parent()
* @package userforms
*/
-class EditableCustomRule extends DataObject {
+class EditableCustomRule extends DataObject
+{
- private static $condition_options = array(
- "IsBlank" => "Is blank",
- "IsNotBlank" => "Is not blank",
- "HasValue" => "Equals",
- "ValueNot" => "Doesn't equal",
- "ValueLessThan" => "Less than",
- "ValueLessThanEqual" => "Less than or equal",
- "ValueGreaterThan" => "Greater than",
- "ValueGreaterThanEqual" => "Greater than or equal"
- );
+ private static $condition_options = array(
+ "IsBlank" => "Is blank",
+ "IsNotBlank" => "Is not blank",
+ "HasValue" => "Equals",
+ "ValueNot" => "Doesn't equal",
+ "ValueLessThan" => "Less than",
+ "ValueLessThanEqual" => "Less than or equal",
+ "ValueGreaterThan" => "Greater than",
+ "ValueGreaterThanEqual" => "Greater than or equal"
+ );
- private static $db = array(
- 'Display' => 'Enum("Show,Hide")',
- 'ConditionOption' => 'Enum("IsBlank,IsNotBlank,HasValue,ValueNot,ValueLessThan,ValueLessThanEqual,ValueGreaterThan,ValueGreaterThanEqual")',
- 'FieldValue' => 'Varchar(255)'
- );
+ private static $db = array(
+ 'Display' => 'Enum("Show,Hide")',
+ 'ConditionOption' => 'Enum("IsBlank,IsNotBlank,HasValue,ValueNot,ValueLessThan,ValueLessThanEqual,ValueGreaterThan,ValueGreaterThanEqual")',
+ 'FieldValue' => 'Varchar(255)'
+ );
- private static $has_one = array(
- 'Parent' => 'EditableFormField',
- 'ConditionField' => 'EditableFormField'
- );
+ private static $has_one = array(
+ 'Parent' => 'EditableFormField',
+ 'ConditionField' => 'EditableFormField'
+ );
- /**
- * Built in extensions required
- *
- * @config
- * @var array
- */
- private static $extensions = array(
- "Versioned('Stage', 'Live')"
- );
+ /**
+ * Built in extensions required
+ *
+ * @config
+ * @var array
+ */
+ private static $extensions = array(
+ "Versioned('Stage', 'Live')"
+ );
- /**
- * Publish this custom rule to the live site
- *
- * Wrapper for the {@link Versioned} publish function
- */
- public function doPublish($fromStage, $toStage, $createNewVersion = false) {
- $this->publish($fromStage, $toStage, $createNewVersion);
- }
+ /**
+ * Publish this custom rule to the live site
+ *
+ * Wrapper for the {@link Versioned} publish function
+ */
+ public function doPublish($fromStage, $toStage, $createNewVersion = false)
+ {
+ $this->publish($fromStage, $toStage, $createNewVersion);
+ }
- /**
- * Delete this custom rule from a given stage
- *
- * Wrapper for the {@link Versioned} deleteFromStage function
- */
- public function doDeleteFromStage($stage) {
- $this->deleteFromStage($stage);
- }
+ /**
+ * Delete this custom rule from a given stage
+ *
+ * Wrapper for the {@link Versioned} deleteFromStage function
+ */
+ public function doDeleteFromStage($stage)
+ {
+ $this->deleteFromStage($stage);
+ }
/**
* @param Member $member
* @return bool
*/
- public function canDelete($member = null) {
- return $this->canEdit($member);
- }
+ public function canDelete($member = null)
+ {
+ return $this->canEdit($member);
+ }
/**
* @param Member $member
* @return bool
*/
- public function canEdit($member = null) {
+ public function canEdit($member = null)
+ {
return $this->Parent()->canEdit($member);
- }
+ }
/**
* @param Member $member
* @return bool
*/
- public function canView($member = null) {
- return $this->Parent()->canView($member);
- }
+ public function canView($member = null)
+ {
+ return $this->Parent()->canView($member);
+ }
- /**
- * Return whether a user can create an object of this type
- *
+ /**
+ * Return whether a user can create an object of this type
+ *
* @param Member $member
* @param array $context Virtual parameter to allow context to be passed in to check
- * @return bool
- */
- public function canCreate($member = null) {
- // Check parent page
+ * @return bool
+ */
+ public function canCreate($member = null)
+ {
+ // Check parent page
$parent = $this->getCanCreateContext(func_get_args());
- if($parent) {
+ if ($parent) {
return $parent->canEdit($member);
}
// Fall back to secure admin permissions
return parent::canCreate($member);
- }
+ }
/**
* Helper method to check the parent for this object
@@ -108,13 +115,14 @@ class EditableCustomRule extends DataObject {
* @param array $args List of arguments passed to canCreate
* @return DataObject Some parent dataobject to inherit permissions from
*/
- protected function getCanCreateContext($args) {
+ protected function getCanCreateContext($args)
+ {
// Inspect second parameter to canCreate for a 'Parent' context
- if(isset($args[1]['Parent'])) {
+ if (isset($args[1]['Parent'])) {
return $args[1]['Parent'];
}
// 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();
}
@@ -126,7 +134,8 @@ class EditableCustomRule extends DataObject {
* @param Member $member
* @return bool
*/
- public function canPublish($member = null) {
+ public function canPublish($member = null)
+ {
return $this->canEdit($member);
}
@@ -134,7 +143,8 @@ class EditableCustomRule extends DataObject {
* @param Member $member
* @return bool
*/
- public function canUnpublish($member = null) {
+ public function canUnpublish($member = null)
+ {
return $this->canDelete($member);
}
}
diff --git a/code/model/UserDefinedForm.php b/code/model/UserDefinedForm.php
index 0e6935d..24c6336 100755
--- a/code/model/UserDefinedForm.php
+++ b/code/model/UserDefinedForm.php
@@ -4,178 +4,180 @@
* @package userforms
*/
-class UserDefinedForm extends Page {
+class UserDefinedForm extends Page
+{
+
+ /**
+ * @var string
+ */
+ private static $icon = 'userforms/images/sitetree_icon.png';
- /**
- * @var string
- */
- private static $icon = 'userforms/images/sitetree_icon.png';
+ /**
+ * @var string
+ */
+ private static $description = 'Adds a customizable form.';
- /**
- * @var string
- */
- private static $description = 'Adds a customizable form.';
+ /**
+ * @var string Required Identifier
+ */
+ private static $required_identifier = null;
- /**
- * @var string Required Identifier
- */
- private static $required_identifier = null;
+ /**
+ * @var string
+ */
+ private static $email_template_directory = 'userforms/templates/email/';
- /**
- * @var string
- */
- private static $email_template_directory = 'userforms/templates/email/';
-
- /**
- * Should this module automatically upgrade on dev/build?
- *
- * @config
- * @var bool
- */
- private static $upgrade_on_build = true;
-
- /**
- * Built in extensions required by this page
- * @config
- * @var array
- */
- private static $extensions = array(
- 'UserFormFieldEditorExtension'
- );
-
- /**
- * @var array Fields on the user defined form page.
- */
- private static $db = array(
- "SubmitButtonText" => "Varchar",
- "ClearButtonText" => "Varchar",
- "OnCompleteMessage" => "HTMLText",
- "ShowClearButton" => "Boolean",
- 'DisableSaveSubmissions' => 'Boolean',
- 'EnableLiveValidation' => 'Boolean',
- 'HideFieldLabels' => 'Boolean',
- 'DisplayErrorMessagesAtTop' => 'Boolean',
- 'DisableAuthenicatedFinishAction' => 'Boolean',
- 'DisableCsrfSecurityToken' => 'Boolean'
- );
-
- /**
- * @var array Default values of variables when this page is created
- */
- private static $defaults = array(
- 'Content' => '$UserDefinedForm',
- 'DisableSaveSubmissions' => 0,
- 'OnCompleteMessage' => '
Thanks, we\'ve received your submission.
'
- );
-
- /**
- * @var array
- */
- private static $has_many = array(
- "Submissions" => "SubmittedForm",
- "EmailRecipients" => "UserDefinedForm_EmailRecipient"
- );
-
- /**
- * @var array
- * @config
- */
- private static $casting = array(
- 'ErrorContainerID' => 'Text'
- );
-
- /**
- * Error container selector which matches the element for grouped messages
- *
- * @var string
- * @config
- */
- private static $error_container_id = 'error-container';
-
- /**
- * The configuration used to determine whether a confirmation message is to
- * appear when navigating away from a partially completed form.
- *
- * @var boolean
- * @config
- */
- private static $enable_are_you_sure = true;
-
- /**
- * @var bool
+ /**
+ * Should this module automatically upgrade on dev/build?
+ *
* @config
- */
- private static $recipients_warning_enabled = false;
+ * @var bool
+ */
+ private static $upgrade_on_build = true;
- /**
- * Temporary storage of field ids when the form is duplicated.
- * Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
- * @var array
- */
- protected $fieldsFromTo = array();
+ /**
+ * Built in extensions required by this page
+ * @config
+ * @var array
+ */
+ private static $extensions = array(
+ 'UserFormFieldEditorExtension'
+ );
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
+ /**
+ * @var array Fields on the user defined form page.
+ */
+ private static $db = array(
+ "SubmitButtonText" => "Varchar",
+ "ClearButtonText" => "Varchar",
+ "OnCompleteMessage" => "HTMLText",
+ "ShowClearButton" => "Boolean",
+ 'DisableSaveSubmissions' => 'Boolean',
+ 'EnableLiveValidation' => 'Boolean',
+ 'HideFieldLabels' => 'Boolean',
+ 'DisplayErrorMessagesAtTop' => 'Boolean',
+ 'DisableAuthenicatedFinishAction' => 'Boolean',
+ 'DisableCsrfSecurityToken' => 'Boolean'
+ );
- $self = $this;
+ /**
+ * @var array Default values of variables when this page is created
+ */
+ private static $defaults = array(
+ 'Content' => '$UserDefinedForm',
+ 'DisableSaveSubmissions' => 0,
+ 'OnCompleteMessage' => '
Thanks, we\'ve received your submission.
'
+ );
- $this->beforeUpdateCMSFields(function($fields) use ($self) {
+ /**
+ * @var array
+ */
+ private static $has_many = array(
+ "Submissions" => "SubmittedForm",
+ "EmailRecipients" => "UserDefinedForm_EmailRecipient"
+ );
- // define tabs
- $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
- $fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients'));
- $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
+ /**
+ * @var array
+ * @config
+ */
+ private static $casting = array(
+ 'ErrorContainerID' => 'Text'
+ );
- // text to show on complete
- $onCompleteFieldSet = new CompositeField(
- $label = new LabelField('OnCompleteMessageLabel',_t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
- $editor = new HtmlEditorField( 'OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
- );
+ /**
+ * Error container selector which matches the element for grouped messages
+ *
+ * @var string
+ * @config
+ */
+ private static $error_container_id = 'error-container';
- $onCompleteFieldSet->addExtraClass('field');
+ /**
+ * The configuration used to determine whether a confirmation message is to
+ * appear when navigating away from a partially completed form.
+ *
+ * @var boolean
+ * @config
+ */
+ private static $enable_are_you_sure = true;
- $editor->setRows(3);
- $label->addExtraClass('left');
+ /**
+ * @var bool
+ * @config
+ */
+ private static $recipients_warning_enabled = false;
- // Define config for email recipients
- $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
- $emailRecipientsConfig->getComponentByType('GridFieldAddNewButton')
- ->setButtonName(
- _t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
- );
+ /**
+ * Temporary storage of field ids when the form is duplicated.
+ * Example layout: array('EditableCheckbox3' => 'EditableCheckbox14')
+ * @var array
+ */
+ protected $fieldsFromTo = array();
- // who do we email on submission
- $emailRecipients = new GridField(
- 'EmailRecipients',
- _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'),
- $self->EmailRecipients(),
- $emailRecipientsConfig
- );
- $emailRecipients
- ->getConfig()
- ->getComponentByType('GridFieldDetailForm')
- ->setItemRequestClass('UserFormRecipientItemRequest');
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
- $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
- $fields->addFieldToTab('Root.Recipients', $emailRecipients);
- $fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
+ $self = $this;
+
+ $this->beforeUpdateCMSFields(function ($fields) use ($self) {
+
+ // define tabs
+ $fields->findOrMakeTab('Root.FormOptions', _t('UserDefinedForm.CONFIGURATION', 'Configuration'));
+ $fields->findOrMakeTab('Root.Recipients', _t('UserDefinedForm.RECIPIENTS', 'Recipients'));
+ $fields->findOrMakeTab('Root.Submissions', _t('UserDefinedForm.SUBMISSIONS', 'Submissions'));
+
+ // text to show on complete
+ $onCompleteFieldSet = new CompositeField(
+ $label = new LabelField('OnCompleteMessageLabel', _t('UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')),
+ $editor = new HtmlEditorField('OnCompleteMessage', '', _t('UserDefinedForm.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
+ );
+
+ $onCompleteFieldSet->addExtraClass('field');
+
+ $editor->setRows(3);
+ $label->addExtraClass('left');
+
+ // Define config for email recipients
+ $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
+ $emailRecipientsConfig->getComponentByType('GridFieldAddNewButton')
+ ->setButtonName(
+ _t('UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
+ );
+
+ // who do we email on submission
+ $emailRecipients = new GridField(
+ 'EmailRecipients',
+ _t('UserDefinedForm.EMAILRECIPIENTS', 'Email Recipients'),
+ $self->EmailRecipients(),
+ $emailRecipientsConfig
+ );
+ $emailRecipients
+ ->getConfig()
+ ->getComponentByType('GridFieldDetailForm')
+ ->setItemRequestClass('UserFormRecipientItemRequest');
+
+ $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
+ $fields->addFieldToTab('Root.Recipients', $emailRecipients);
+ $fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
- // view the submissions
- $submissions = new GridField(
- 'Submissions',
- _t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
- $self->Submissions()->sort('Created', 'DESC')
- );
+ // view the submissions
+ $submissions = new GridField(
+ 'Submissions',
+ _t('UserDefinedForm.SUBMISSIONS', 'Submissions'),
+ $self->Submissions()->sort('Created', 'DESC')
+ );
- // make sure a numeric not a empty string is checked against this int column for SQL server
- $parentID = (!empty($self->ID)) ? (int) $self->ID : 0;
+ // make sure a numeric not a empty string is checked against this int column for SQL server
+ $parentID = (!empty($self->ID)) ? (int) $self->ID : 0;
- // get a list of all field names and values used for print and export CSV views of the GridField below.
- $columnSQL = <<map() as $name => $title) {
- $columns[$name] = trim(strtr($title, '.', ' '));
- }
+ // Sanitise periods in title
+ $columns = array();
+ foreach (DB::query($columnSQL)->map() as $name => $title) {
+ $columns[$name] = trim(strtr($title, '.', ' '));
+ }
- $config = new GridFieldConfig();
- $config->addComponent(new GridFieldToolbarHeader());
- $config->addComponent($sort = new GridFieldSortableHeader());
- $config->addComponent($filter = new UserFormsGridFieldFilterHeader());
- $config->addComponent(new GridFieldDataColumns());
- $config->addComponent(new GridFieldEditButton());
- $config->addComponent(new GridFieldDeleteAction());
- $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
- $config->addComponent($pagination = new GridFieldPaginator(25));
- $config->addComponent(new GridFieldDetailForm());
- $config->addComponent(new GridFieldButtonRow('after'));
- $config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
- $config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
+ $config = new GridFieldConfig();
+ $config->addComponent(new GridFieldToolbarHeader());
+ $config->addComponent($sort = new GridFieldSortableHeader());
+ $config->addComponent($filter = new UserFormsGridFieldFilterHeader());
+ $config->addComponent(new GridFieldDataColumns());
+ $config->addComponent(new GridFieldEditButton());
+ $config->addComponent(new GridFieldDeleteAction());
+ $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
+ $config->addComponent($pagination = new GridFieldPaginator(25));
+ $config->addComponent(new GridFieldDetailForm());
+ $config->addComponent(new GridFieldButtonRow('after'));
+ $config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
+ $config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
- /**
- * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
- */
- if(class_exists('GridFieldBulkManager')) {
- $config->addComponent(new GridFieldBulkManager());
- }
+ /**
+ * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
+ */
+ if (class_exists('GridFieldBulkManager')) {
+ $config->addComponent(new GridFieldBulkManager());
+ }
- $sort->setThrowExceptionOnBadDataType(false);
- $filter->setThrowExceptionOnBadDataType(false);
- $pagination->setThrowExceptionOnBadDataType(false);
+ $sort->setThrowExceptionOnBadDataType(false);
+ $filter->setThrowExceptionOnBadDataType(false);
+ $pagination->setThrowExceptionOnBadDataType(false);
- // attach every column to the print view form
- $columns['Created'] = 'Created';
- $filter->setColumns($columns);
+ // attach every column to the print view form
+ $columns['Created'] = 'Created';
+ $filter->setColumns($columns);
- // print configuration
+ // print configuration
- $print->setPrintHasHeader(true);
- $print->setPrintColumns($columns);
+ $print->setPrintHasHeader(true);
+ $print->setPrintColumns($columns);
- // export configuration
- $export->setCsvHasHeader(true);
- $export->setExportColumns($columns);
+ // export configuration
+ $export->setCsvHasHeader(true);
+ $export->setExportColumns($columns);
- $submissions->setConfig($config);
- $fields->addFieldToTab('Root.Submissions', $submissions);
- $fields->addFieldToTab('Root.FormOptions', new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')));
+ $submissions->setConfig($config);
+ $fields->addFieldToTab('Root.Submissions', $submissions);
+ $fields->addFieldToTab('Root.FormOptions', new CheckboxField('DisableSaveSubmissions', _t('UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')));
- });
+ });
- $fields = parent::getCMSFields();
+ $fields = parent::getCMSFields();
- if($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
- $fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
- "
" . _t("UserDefinedForm.NORECIPIENTS",
- "Warning: You have not configured any recipients. Form submissions may be missed.")
- . "
"), "Title");
- }
+ if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) {
+ $fields->addFieldToTab("Root.Main", new LiteralField("EmailRecipientsWarning",
+ "
" . _t("UserDefinedForm.NORECIPIENTS",
+ "Warning: You have not configured any recipients. Form submissions may be missed.")
+ . "
"), "Title");
+ }
- return $fields;
- }
+ return $fields;
+ }
- /**
- * Allow overriding the EmailRecipients on a {@link DataExtension}
- * so you can customise who receives an email.
- * Converts the RelationList to an ArrayList so that manipulation
- * of the original source data isn't possible.
- *
- * @return ArrayList
- */
- public function FilteredEmailRecipients($data = null, $form = null) {
- $recipients = new ArrayList($this->EmailRecipients()->toArray());
+ /**
+ * Allow overriding the EmailRecipients on a {@link DataExtension}
+ * so you can customise who receives an email.
+ * Converts the RelationList to an ArrayList so that manipulation
+ * of the original source data isn't possible.
+ *
+ * @return ArrayList
+ */
+ public function FilteredEmailRecipients($data = null, $form = null)
+ {
+ $recipients = new ArrayList($this->EmailRecipients()->toArray());
- // Filter by rules
- $recipients = $recipients->filterByCallback(function($recipient) use ($data, $form) {
- return $recipient->canSend($data, $form);
- });
+ // Filter by rules
+ $recipients = $recipients->filterByCallback(function ($recipient) use ($data, $form) {
+ return $recipient->canSend($data, $form);
+ });
- $this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
+ $this->extend('updateFilteredEmailRecipients', $recipients, $data, $form);
- return $recipients;
- }
+ return $recipients;
+ }
- /**
- * Custom options for the form. You can extend the built in options by
- * using {@link updateFormOptions()}
- *
- * @return FieldList
- */
- public function getFormOptions() {
- $submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
- $clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
+ /**
+ * Custom options for the form. You can extend the built in options by
+ * using {@link updateFormOptions()}
+ *
+ * @return FieldList
+ */
+ public function getFormOptions()
+ {
+ $submit = ($this->SubmitButtonText) ? $this->SubmitButtonText : _t('UserDefinedForm.SUBMITBUTTON', 'Submit');
+ $clear = ($this->ClearButtonText) ? $this->ClearButtonText : _t('UserDefinedForm.CLEARBUTTON', 'Clear');
- $options = new FieldList(
- new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
- new TextField("ClearButtonText", _t('UserDefinedForm.TEXTONCLEAR', 'Text on clear button:'), $clear),
- new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
- new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
- new CheckboxField("HideFieldLabels", _t('UserDefinedForm.HIDEFIELDLABELS', 'Hide field labels')),
- new CheckboxField("DisplayErrorMessagesAtTop", _t('UserDefinedForm.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
- new CheckboxField('DisableCsrfSecurityToken', _t('UserDefinedForm.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
- new CheckboxField('DisableAuthenicatedFinishAction', _t('UserDefinedForm.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
- );
+ $options = new FieldList(
+ new TextField("SubmitButtonText", _t('UserDefinedForm.TEXTONSUBMIT', 'Text on submit button:'), $submit),
+ new TextField("ClearButtonText", _t('UserDefinedForm.TEXTONCLEAR', 'Text on clear button:'), $clear),
+ new CheckboxField("ShowClearButton", _t('UserDefinedForm.SHOWCLEARFORM', 'Show Clear Form Button'), $this->ShowClearButton),
+ new CheckboxField("EnableLiveValidation", _t('UserDefinedForm.ENABLELIVEVALIDATION', 'Enable live validation')),
+ new CheckboxField("HideFieldLabels", _t('UserDefinedForm.HIDEFIELDLABELS', 'Hide field labels')),
+ new CheckboxField("DisplayErrorMessagesAtTop", _t('UserDefinedForm.DISPLAYERRORMESSAGESATTOP', 'Display error messages above the form?')),
+ new CheckboxField('DisableCsrfSecurityToken', _t('UserDefinedForm.DISABLECSRFSECURITYTOKEN', 'Disable CSRF Token')),
+ new CheckboxField('DisableAuthenicatedFinishAction', _t('UserDefinedForm.DISABLEAUTHENICATEDFINISHACTION', 'Disable Authentication on finish action'))
+ );
- $this->extend('updateFormOptions', $options);
+ $this->extend('updateFormOptions', $options);
- return $options;
- }
+ return $options;
+ }
- /**
- * Get the HTML id of the error container displayed above the form.
- *
- * @return string
- */
- public function getErrorContainerID() {
- return $this->config()->error_container_id;
- }
+ /**
+ * Get the HTML id of the error container displayed above the form.
+ *
+ * @return string
+ */
+ public function getErrorContainerID()
+ {
+ return $this->config()->error_container_id;
+ }
- public function requireDefaultRecords() {
- parent::requireDefaultRecords();
+ public function requireDefaultRecords()
+ {
+ parent::requireDefaultRecords();
- if(!$this->config()->upgrade_on_build) {
- return;
- }
+ if (!$this->config()->upgrade_on_build) {
+ return;
+ }
- // Perform migrations
- Injector::inst()
- ->create('UserFormsUpgradeService')
- ->setQuiet(true)
- ->run();
+ // Perform migrations
+ Injector::inst()
+ ->create('UserFormsUpgradeService')
+ ->setQuiet(true)
+ ->run();
- DB::alteration_message('Migrated userforms', 'changed');
- }
+ DB::alteration_message('Migrated userforms', 'changed');
+ }
- /**
- * Validate formfields
- */
- public function getCMSValidator() {
- return new UserFormValidator();
- }
+ /**
+ * Validate formfields
+ */
+ public function getCMSValidator()
+ {
+ return new UserFormValidator();
+ }
}
/**
@@ -332,232 +339,238 @@ SQL;
* @package userforms
*/
-class UserDefinedForm_Controller extends Page_Controller {
+class UserDefinedForm_Controller extends Page_Controller
+{
- private static $finished_anchor = '#uff';
+ private static $finished_anchor = '#uff';
- private static $allowed_actions = array(
- 'index',
- 'ping',
- 'Form',
- 'finished'
- );
+ private static $allowed_actions = array(
+ 'index',
+ 'ping',
+ 'Form',
+ 'finished'
+ );
- public function init() {
- parent::init();
+ public function init()
+ {
+ parent::init();
- // load the jquery
- $lang = i18n::get_lang_from_locale(i18n::get_locale());
- Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
- Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js');
- Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery-validate/jquery.validate.min.js');
- Requirements::add_i18n_javascript(USERFORMS_DIR . '/javascript/lang');
- Requirements::javascript(USERFORMS_DIR . '/javascript/UserForm.js');
+ // load the jquery
+ $lang = i18n::get_lang_from_locale(i18n::get_locale());
+ Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
+ Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js');
+ Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery-validate/jquery.validate.min.js');
+ Requirements::add_i18n_javascript(USERFORMS_DIR . '/javascript/lang');
+ Requirements::javascript(USERFORMS_DIR . '/javascript/UserForm.js');
- Requirements::javascript(
- USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js"
- );
- Requirements::javascript(
- USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
- );
- if($this->HideFieldLabels) {
- Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
- }
+ Requirements::javascript(
+ USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js"
+ );
+ Requirements::javascript(
+ USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
+ );
+ if ($this->HideFieldLabels) {
+ Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
+ }
- // Bind a confirmation message when navigating away from a partially completed form.
- $page = $this->data();
- if($page::config()->enable_are_you_sure) {
- Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
- }
- }
+ // Bind a confirmation message when navigating away from a partially completed form.
+ $page = $this->data();
+ if ($page::config()->enable_are_you_sure) {
+ Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
+ }
+ }
- /**
- * Using $UserDefinedForm in the Content area of the page shows
- * where the form should be rendered into. If it does not exist
- * then default back to $Form.
- *
- * @return array
- */
- public function index() {
- if($this->Content && $form = $this->Form()) {
- $hasLocation = stristr($this->Content, '$UserDefinedForm');
- if($hasLocation) {
- $content = preg_replace('/(
]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
- return array(
- 'Content' => DBField::create_field('HTMLText', $content),
- 'Form' => ""
- );
- }
- }
+ /**
+ * Using $UserDefinedForm in the Content area of the page shows
+ * where the form should be rendered into. If it does not exist
+ * then default back to $Form.
+ *
+ * @return array
+ */
+ public function index()
+ {
+ if ($this->Content && $form = $this->Form()) {
+ $hasLocation = stristr($this->Content, '$UserDefinedForm');
+ if ($hasLocation) {
+ $content = preg_replace('/(
]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
+ return array(
+ 'Content' => DBField::create_field('HTMLText', $content),
+ 'Form' => ""
+ );
+ }
+ }
- return array(
- 'Content' => DBField::create_field('HTMLText', $this->Content),
- 'Form' => $this->Form()
- );
- }
+ return array(
+ 'Content' => DBField::create_field('HTMLText', $this->Content),
+ 'Form' => $this->Form()
+ );
+ }
- /**
- * Keep the session alive for the user.
- *
- * @return int
- */
- public function ping() {
- return 1;
- }
+ /**
+ * Keep the session alive for the user.
+ *
+ * @return int
+ */
+ public function ping()
+ {
+ return 1;
+ }
- /**
- * Get the form for the page. Form can be modified by calling {@link updateForm()}
- * on a UserDefinedForm extension.
- *
- * @return Forms
- */
- public function Form() {
- $form = UserForm::create($this);
- $this->generateConditionalJavascript();
- return $form;
- }
+ /**
+ * Get the form for the page. Form can be modified by calling {@link updateForm()}
+ * on a UserDefinedForm extension.
+ *
+ * @return Forms
+ */
+ public function Form()
+ {
+ $form = UserForm::create($this);
+ $this->generateConditionalJavascript();
+ return $form;
+ }
- /**
- * Generate the javascript for the conditional field show / hiding logic.
- *
- * @return void
- */
- public function generateConditionalJavascript() {
- $default = "";
- $rules = "";
+ /**
+ * Generate the javascript for the conditional field show / hiding logic.
+ *
+ * @return void
+ */
+ public function generateConditionalJavascript()
+ {
+ $default = "";
+ $rules = "";
- $watch = array();
- $watchLoad = array();
+ $watch = array();
+ $watchLoad = array();
- if($this->Fields()) {
- foreach($this->Fields() as $field) {
- $holderSelector = $field->getSelectorHolder();
+ if ($this->Fields()) {
+ foreach ($this->Fields() as $field) {
+ $holderSelector = $field->getSelectorHolder();
- // Is this Field Show by Default
- if(!$field->ShowOnLoad) {
- $default .= "{$holderSelector}.hide().trigger('userform.field.hide');\n";
- }
+ // Is this Field Show by Default
+ if (!$field->ShowOnLoad) {
+ $default .= "{$holderSelector}.hide().trigger('userform.field.hide');\n";
+ }
- // Check for field dependencies / default
- foreach($field->EffectiveDisplayRules() as $rule) {
+ // Check for field dependencies / default
+ foreach ($field->EffectiveDisplayRules() as $rule) {
- // Get the field which is effected
- $formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
+ // Get the field which is effected
+ $formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
- // Skip deleted fields
- if(!$formFieldWatch) {
- continue;
- }
+ // Skip deleted fields
+ if (!$formFieldWatch) {
+ continue;
+ }
- $fieldToWatch = $formFieldWatch->getSelectorField($rule);
- $fieldToWatchOnLoad = $formFieldWatch->getSelectorField($rule, true);
+ $fieldToWatch = $formFieldWatch->getSelectorField($rule);
+ $fieldToWatchOnLoad = $formFieldWatch->getSelectorField($rule, true);
- // show or hide?
- $view = ($rule->Display == 'Hide') ? 'hide' : 'show';
- $opposite = ($view == "show") ? "hide" : "show";
+ // show or hide?
+ $view = ($rule->Display == 'Hide') ? 'hide' : 'show';
+ $opposite = ($view == "show") ? "hide" : "show";
- // what action do we need to keep track of. Something nicer here maybe?
- // @todo encapulsation
- $action = "change";
+ // what action do we need to keep track of. Something nicer here maybe?
+ // @todo encapulsation
+ $action = "change";
- if($formFieldWatch instanceof EditableTextField) {
- $action = "keyup";
- }
+ if ($formFieldWatch instanceof EditableTextField) {
+ $action = "keyup";
+ }
- // is this field a special option field
- $checkboxField = false;
- $radioField = false;
+ // is this field a special option field
+ $checkboxField = false;
+ $radioField = false;
- if(in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) {
- $action = "click";
- $checkboxField = true;
- } else if ($formFieldWatch->ClassName == "EditableRadioField") {
- $radioField = true;
- }
+ if (in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) {
+ $action = "click";
+ $checkboxField = true;
+ } elseif ($formFieldWatch->ClassName == "EditableRadioField") {
+ $radioField = true;
+ }
- // and what should we evaluate
- switch($rule->ConditionOption) {
- case 'IsNotBlank':
- $expression = ($checkboxField || $radioField) ? '$(this).is(":checked")' :'$(this).val() != ""';
+ // and what should we evaluate
+ switch ($rule->ConditionOption) {
+ case 'IsNotBlank':
+ $expression = ($checkboxField || $radioField) ? '$(this).is(":checked")' :'$(this).val() != ""';
- break;
- case 'IsBlank':
- $expression = ($checkboxField || $radioField) ? '!($(this).is(":checked"))' : '$(this).val() == ""';
+ break;
+ case 'IsBlank':
+ $expression = ($checkboxField || $radioField) ? '!($(this).is(":checked"))' : '$(this).val() == ""';
- break;
- case 'HasValue':
- if ($checkboxField) {
- $expression = '$(this).prop("checked")';
- } else if ($radioField) {
- // 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 .'"';
- } else {
- $expression = '$(this).val() == "'. $rule->FieldValue .'"';
- }
+ break;
+ case 'HasValue':
+ if ($checkboxField) {
+ $expression = '$(this).prop("checked")';
+ } elseif ($radioField) {
+ // 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 .'"';
+ } else {
+ $expression = '$(this).val() == "'. $rule->FieldValue .'"';
+ }
- break;
- case 'ValueLessThan':
- $expression = '$(this).val() < parseFloat("'. $rule->FieldValue .'")';
+ break;
+ case 'ValueLessThan':
+ $expression = '$(this).val() < parseFloat("'. $rule->FieldValue .'")';
- break;
- case 'ValueLessThanEqual':
- $expression = '$(this).val() <= parseFloat("'. $rule->FieldValue .'")';
+ break;
+ case 'ValueLessThanEqual':
+ $expression = '$(this).val() <= parseFloat("'. $rule->FieldValue .'")';
- break;
- case 'ValueGreaterThan':
- $expression = '$(this).val() > parseFloat("'. $rule->FieldValue .'")';
+ break;
+ case 'ValueGreaterThan':
+ $expression = '$(this).val() > parseFloat("'. $rule->FieldValue .'")';
- break;
- case 'ValueGreaterThanEqual':
- $expression = '$(this).val() >= parseFloat("'. $rule->FieldValue .'")';
+ break;
+ case 'ValueGreaterThanEqual':
+ $expression = '$(this).val() >= parseFloat("'. $rule->FieldValue .'")';
- break;
- default: // ==HasNotValue
- if ($checkboxField) {
- $expression = '!$(this).prop("checked")';
- } else if ($radioField) {
- // 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 .'"';
- } else {
- $expression = '$(this).val() != "'. $rule->FieldValue .'"';
- }
+ break;
+ default: // ==HasNotValue
+ if ($checkboxField) {
+ $expression = '!$(this).prop("checked")';
+ } elseif ($radioField) {
+ // 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 .'"';
+ } else {
+ $expression = '$(this).val() != "'. $rule->FieldValue .'"';
+ }
- break;
- }
+ break;
+ }
- if(!isset($watch[$fieldToWatch])) {
- $watch[$fieldToWatch] = array();
- }
+ if (!isset($watch[$fieldToWatch])) {
+ $watch[$fieldToWatch] = array();
+ }
- $watch[$fieldToWatch][] = array(
- 'expression' => $expression,
- 'holder_selector' => $holderSelector,
- 'view' => $view,
- 'opposite' => $opposite,
- 'action' => $action
- );
+ $watch[$fieldToWatch][] = array(
+ 'expression' => $expression,
+ 'holder_selector' => $holderSelector,
+ 'view' => $view,
+ 'opposite' => $opposite,
+ 'action' => $action
+ );
- $watchLoad[$fieldToWatchOnLoad] = true;
- }
- }
- }
+ $watchLoad[$fieldToWatchOnLoad] = true;
+ }
+ }
+ }
- if($watch) {
- foreach($watch as $key => $values) {
- $logic = array();
- $actions = array();
+ if ($watch) {
+ foreach ($watch as $key => $values) {
+ $logic = array();
+ $actions = array();
- foreach($values as $rule) {
- // Assign action
- $actions[$rule['action']] = $rule['action'];
+ foreach ($values as $rule) {
+ // Assign action
+ $actions[$rule['action']] = $rule['action'];
- // Assign behaviour
- $expression = $rule['expression'];
- $holder = $rule['holder_selector'];
- $view = $rule['view']; // hide or show
- $opposite = $rule['opposite'];
- // Generated javascript for triggering visibility
- $logic[] = <<<"EOS"
+ // Assign behaviour
+ $expression = $rule['expression'];
+ $holder = $rule['holder_selector'];
+ $view = $rule['view']; // hide or show
+ $opposite = $rule['opposite'];
+ // Generated javascript for triggering visibility
+ $logic[] = <<<"EOS"
if({$expression}) {
{$holder}
.{$view}()
@@ -568,33 +581,33 @@ if({$expression}) {
.trigger('userform.field.{$opposite}');
}
EOS;
- }
+ }
- $logic = implode("\n", $logic);
- $rules .= $key.".each(function() {\n
+ $logic = implode("\n", $logic);
+ $rules .= $key.".each(function() {\n
$(this).data('userformConditions', function() {\n
$logic\n
}); \n
});\n";
- foreach($actions as $action) {
- $rules .= $key.".$action(function() {
+ foreach ($actions as $action) {
+ $rules .= $key.".$action(function() {
$(this).data('userformConditions').call(this);\n
});\n";
- }
- }
- }
+ }
+ }
+ }
- if($watchLoad) {
- foreach($watchLoad as $key => $value) {
- $rules .= $key.".each(function() {
+ if ($watchLoad) {
+ foreach ($watchLoad as $key => $value) {
+ $rules .= $key.".each(function() {
$(this).data('userformConditions').call(this);\n
});\n";
- }
- }
+ }
+ }
- // Only add customScript if $default or $rules is defined
- if($default || $rules) {
- Requirements::customScript(<<SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
- $submittedForm->ParentID = $this->ID;
+ /**
+ * Process the form that is submitted through the site
+ *
+ * {@see UserForm::validate()} for validation step prior to processing
+ *
+ * @param array $data
+ * @param Form $form
+ *
+ * @return Redirection
+ */
+ public function process($data, $form)
+ {
+ $submittedForm = Object::create('SubmittedForm');
+ $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
+ $submittedForm->ParentID = $this->ID;
- // if saving is not disabled save now to generate the ID
- if(!$this->DisableSaveSubmissions) {
- $submittedForm->write();
- }
+ // if saving is not disabled save now to generate the ID
+ if (!$this->DisableSaveSubmissions) {
+ $submittedForm->write();
+ }
- $attachments = array();
- $submittedFields = new ArrayList();
+ $attachments = array();
+ $submittedFields = new ArrayList();
- foreach($this->Fields() as $field) {
- if(!$field->showInReports()) {
- continue;
- }
+ foreach ($this->Fields() as $field) {
+ if (!$field->showInReports()) {
+ continue;
+ }
- $submittedField = $field->getSubmittedFormField();
- $submittedField->ParentID = $submittedForm->ID;
- $submittedField->Name = $field->Name;
- $submittedField->Title = $field->getField('Title');
+ $submittedField = $field->getSubmittedFormField();
+ $submittedField->ParentID = $submittedForm->ID;
+ $submittedField->Name = $field->Name;
+ $submittedField->Title = $field->getField('Title');
- // save the value from the data
- if($field->hasMethod('getValueFromData')) {
- $submittedField->Value = $field->getValueFromData($data);
- } else {
- if(isset($data[$field->Name])) {
- $submittedField->Value = $data[$field->Name];
- }
- }
+ // save the value from the data
+ if ($field->hasMethod('getValueFromData')) {
+ $submittedField->Value = $field->getValueFromData($data);
+ } else {
+ if (isset($data[$field->Name])) {
+ $submittedField->Value = $data[$field->Name];
+ }
+ }
- if(!empty($data[$field->Name])) {
- if(in_array("EditableFileField", $field->getClassAncestry())) {
- if(isset($_FILES[$field->Name])) {
- $foldername = $field->getFormField()->getFolderName();
+ if (!empty($data[$field->Name])) {
+ if (in_array("EditableFileField", $field->getClassAncestry())) {
+ if (isset($_FILES[$field->Name])) {
+ $foldername = $field->getFormField()->getFolderName();
- // create the file from post data
- $upload = new Upload();
- $file = new File();
- $file->ShowInSearch = 0;
- try {
- $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
- } catch( ValidationException $e ) {
- $validationResult = $e->getResult();
- $form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
- Controller::curr()->redirectBack();
- return;
- }
+ // create the file from post data
+ $upload = new Upload();
+ $file = new File();
+ $file->ShowInSearch = 0;
+ try {
+ $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
+ } catch (ValidationException $e) {
+ $validationResult = $e->getResult();
+ $form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
+ Controller::curr()->redirectBack();
+ return;
+ }
- // write file to form field
- $submittedField->UploadedFileID = $file->ID;
+ // write file to form field
+ $submittedField->UploadedFileID = $file->ID;
- // attach a file only if lower than 1MB
- if($file->getAbsoluteSize() < 1024*1024*1) {
- $attachments[] = $file;
- }
- }
- }
- }
+ // attach a file only if lower than 1MB
+ if ($file->getAbsoluteSize() < 1024*1024*1) {
+ $attachments[] = $file;
+ }
+ }
+ }
+ }
- $submittedField->extend('onPopulationFromField', $field);
+ $submittedField->extend('onPopulationFromField', $field);
- if(!$this->DisableSaveSubmissions) {
- $submittedField->write();
- }
+ if (!$this->DisableSaveSubmissions) {
+ $submittedField->write();
+ }
- $submittedFields->push($submittedField);
- }
+ $submittedFields->push($submittedField);
+ }
- $emailData = array(
- "Sender" => Member::currentUser(),
- "Fields" => $submittedFields
- );
+ $emailData = array(
+ "Sender" => Member::currentUser(),
+ "Fields" => $submittedFields
+ );
- $this->extend('updateEmailData', $emailData, $attachments);
+ $this->extend('updateEmailData', $emailData, $attachments);
- // email users on submit.
- if($recipients = $this->FilteredEmailRecipients($data, $form)) {
+ // email users on submit.
+ if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
+ foreach ($recipients as $recipient) {
+ $email = new UserFormRecipientEmail($submittedFields);
+ $mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
+
+ if ($attachments) {
+ foreach ($attachments as $file) {
+ if ($file->ID != 0) {
+ $email->attachFile(
+ $file->Filename,
+ $file->Filename,
+ HTTP::get_mime_type($file->Filename)
+ );
+ }
+ }
+ }
+
+ $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
- foreach($recipients as $recipient) {
- $email = new UserFormRecipientEmail($submittedFields);
- $mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
+ if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
+ $email->setTemplate($recipient->EmailTemplate);
+ }
- if($attachments) {
- foreach($attachments as $file) {
- if($file->ID != 0) {
- $email->attachFile(
- $file->Filename,
- $file->Filename,
- HTTP::get_mime_type($file->Filename)
- );
- }
- }
- }
+ $email->populateTemplate($recipient);
+ $email->populateTemplate($emailData);
+ $email->setFrom($recipient->EmailFrom);
+ $email->setBody($parsedBody);
+ $email->setTo($recipient->EmailAddress);
+ $email->setSubject($recipient->EmailSubject);
- $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
+ if ($recipient->EmailReplyTo) {
+ $email->setReplyTo($recipient->EmailReplyTo);
+ }
- if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
- $email->setTemplate($recipient->EmailTemplate);
- }
+ // check to see if they are a dynamic reply to. eg based on a email field a user selected
+ if ($recipient->SendEmailFromField()) {
+ $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
- $email->populateTemplate($recipient);
- $email->populateTemplate($emailData);
- $email->setFrom($recipient->EmailFrom);
- $email->setBody($parsedBody);
- $email->setTo($recipient->EmailAddress);
- $email->setSubject($recipient->EmailSubject);
+ if ($submittedFormField && is_string($submittedFormField->Value)) {
+ $email->setReplyTo($submittedFormField->Value);
+ }
+ }
+ // check to see if they are a dynamic reciever eg based on a dropdown field a user selected
+ if ($recipient->SendEmailToField()) {
+ $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
- if($recipient->EmailReplyTo) {
- $email->setReplyTo($recipient->EmailReplyTo);
- }
+ if ($submittedFormField && is_string($submittedFormField->Value)) {
+ $email->setTo($submittedFormField->Value);
+ }
+ }
- // check to see if they are a dynamic reply to. eg based on a email field a user selected
- if($recipient->SendEmailFromField()) {
- $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
+ // check to see if there is a dynamic subject
+ if ($recipient->SendEmailSubjectField()) {
+ $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
- if($submittedFormField && is_string($submittedFormField->Value)) {
- $email->setReplyTo($submittedFormField->Value);
- }
- }
- // check to see if they are a dynamic reciever eg based on a dropdown field a user selected
- if($recipient->SendEmailToField()) {
- $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
+ if ($submittedFormField && trim($submittedFormField->Value)) {
+ $email->setSubject($submittedFormField->Value);
+ }
+ }
- if($submittedFormField && is_string($submittedFormField->Value)) {
- $email->setTo($submittedFormField->Value);
- }
- }
+ $this->extend('updateEmail', $email, $recipient, $emailData);
- // check to see if there is a dynamic subject
- if($recipient->SendEmailSubjectField()) {
- $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
+ if ($recipient->SendPlain) {
+ $body = strip_tags($recipient->getEmailBodyContent()) . "\n";
+ if (isset($emailData['Fields']) && !$recipient->HideFormData) {
+ foreach ($emailData['Fields'] as $Field) {
+ $body .= $Field->Title .': '. $Field->Value ." \n";
+ }
+ }
- if($submittedFormField && trim($submittedFormField->Value)) {
- $email->setSubject($submittedFormField->Value);
- }
- }
+ $email->setBody($body);
+ $email->sendPlain();
+ } else {
+ $email->send();
+ }
+ }
+ }
- $this->extend('updateEmail', $email, $recipient, $emailData);
+ $submittedForm->extend('updateAfterProcess');
- if($recipient->SendPlain) {
- $body = strip_tags($recipient->getEmailBodyContent()) . "\n";
- if(isset($emailData['Fields']) && !$recipient->HideFormData) {
- foreach($emailData['Fields'] as $Field) {
- $body .= $Field->Title .': '. $Field->Value ." \n";
- }
- }
+ Session::clear("FormInfo.{$form->FormName()}.errors");
+ Session::clear("FormInfo.{$form->FormName()}.data");
- $email->setBody($body);
- $email->sendPlain();
- }
- else {
- $email->send();
- }
- }
- }
+ $referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
- $submittedForm->extend('updateAfterProcess');
+ // set a session variable from the security ID to stop people accessing
+ // the finished method directly.
+ if (!$this->DisableAuthenicatedFinishAction) {
+ if (isset($data['SecurityID'])) {
+ Session::set('FormProcessed', $data['SecurityID']);
+ } else {
+ // if the form has had tokens disabled we still need to set FormProcessed
+ // to allow us to get through the finshed method
+ if (!$this->Form()->getSecurityToken()->isEnabled()) {
+ $randNum = rand(1, 1000);
+ $randHash = md5($randNum);
+ Session::set('FormProcessed', $randHash);
+ Session::set('FormProcessedNum', $randNum);
+ }
+ }
+ }
- Session::clear("FormInfo.{$form->FormName()}.errors");
- Session::clear("FormInfo.{$form->FormName()}.data");
+ if (!$this->DisableSaveSubmissions) {
+ Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
+ }
- $referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
+ return $this->redirect($this->Link('finished') . $referrer . $this->config()->finished_anchor);
+ }
- // set a session variable from the security ID to stop people accessing
- // the finished method directly.
- if(!$this->DisableAuthenicatedFinishAction) {
- if (isset($data['SecurityID'])) {
- Session::set('FormProcessed',$data['SecurityID']);
- } else {
- // if the form has had tokens disabled we still need to set FormProcessed
- // to allow us to get through the finshed method
- if (!$this->Form()->getSecurityToken()->isEnabled()) {
- $randNum = rand(1, 1000);
- $randHash = md5($randNum);
- Session::set('FormProcessed',$randHash);
- Session::set('FormProcessedNum',$randNum);
- }
- }
- }
+ /**
+ * Allows the use of field values in email body.
+ *
+ * @param ArrayList fields
+ * @return ArrayData
+ */
+ private function getMergeFieldsMap($fields = array())
+ {
+ $data = new ArrayData(array());
- if(!$this->DisableSaveSubmissions) {
- Session::set('userformssubmission'. $this->ID, $submittedForm->ID);
- }
+ foreach ($fields as $field) {
+ $data->setField($field->Name, DBField::create_field('Text', $field->Value));
+ }
- return $this->redirect($this->Link('finished') . $referrer . $this->config()->finished_anchor);
- }
+ return $data;
+ }
- /**
- * Allows the use of field values in email body.
- *
- * @param ArrayList fields
- * @return ArrayData
- */
- private function getMergeFieldsMap($fields = array()) {
- $data = new ArrayData(array());
+ /**
+ * This action handles rendering the "finished" message, which is
+ * customizable by editing the ReceivedFormSubmission template.
+ *
+ * @return ViewableData
+ */
+ public function finished()
+ {
+ $submission = Session::get('userformssubmission'. $this->ID);
- foreach ($fields as $field) {
- $data->setField($field->Name, DBField::create_field('Text', $field->Value));
- }
+ if ($submission) {
+ $submission = SubmittedForm::get()->byId($submission);
+ }
- return $data;
- }
+ $referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
- /**
- * This action handles rendering the "finished" message, which is
- * customizable by editing the ReceivedFormSubmission template.
- *
- * @return ViewableData
- */
- public function finished() {
- $submission = Session::get('userformssubmission'. $this->ID);
+ if (!$this->DisableAuthenicatedFinishAction) {
+ $formProcessed = Session::get('FormProcessed');
- if($submission) {
- $submission = SubmittedForm::get()->byId($submission);
- }
+ if (!isset($formProcessed)) {
+ return $this->redirect($this->Link() . $referrer);
+ } else {
+ $securityID = Session::get('SecurityID');
+ // make sure the session matches the SecurityID and is not left over from another form
+ if ($formProcessed != $securityID) {
+ // they may have disabled tokens on the form
+ $securityID = md5(Session::get('FormProcessedNum'));
+ if ($formProcessed != $securityID) {
+ return $this->redirect($this->Link() . $referrer);
+ }
+ }
+ }
- $referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
+ Session::clear('FormProcessed');
+ }
- if(!$this->DisableAuthenicatedFinishAction) {
- $formProcessed = Session::get('FormProcessed');
-
- if (!isset($formProcessed)) {
- return $this->redirect($this->Link() . $referrer);
- } else {
- $securityID = Session::get('SecurityID');
- // make sure the session matches the SecurityID and is not left over from another form
- if ($formProcessed != $securityID) {
- // they may have disabled tokens on the form
- $securityID = md5(Session::get('FormProcessedNum'));
- if ($formProcessed != $securityID) {
- return $this->redirect($this->Link() . $referrer);
- }
- }
- }
-
- Session::clear('FormProcessed');
- }
-
- return $this->customise(array(
- 'Content' => $this->customise(array(
- 'Submission' => $submission,
- 'Link' => $referrer
- ))->renderWith('ReceivedFormSubmission'),
- 'Form' => '',
- ));
- }
+ return $this->customise(array(
+ 'Content' => $this->customise(array(
+ 'Submission' => $submission,
+ 'Link' => $referrer
+ ))->renderWith('ReceivedFormSubmission'),
+ 'Form' => '',
+ ));
+ }
}
diff --git a/code/model/editableformfields/EditableCheckbox.php b/code/model/editableformfields/EditableCheckbox.php
index 8be026c..bcc2ff8 100755
--- a/code/model/editableformfields/EditableCheckbox.php
+++ b/code/model/editableformfields/EditableCheckbox.php
@@ -7,53 +7,58 @@
* @package userforms
*/
-class EditableCheckbox extends EditableFormField {
+class EditableCheckbox extends EditableFormField
+{
- private static $singular_name = 'Checkbox Field';
+ private static $singular_name = 'Checkbox Field';
- private static $plural_name = 'Checkboxes';
+ private static $plural_name = 'Checkboxes';
- private static $db = array(
- 'CheckedDefault' => 'Boolean' // from CustomSettings
- );
+ private static $db = array(
+ 'CheckedDefault' => 'Boolean' // from CustomSettings
+ );
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- $fields = parent::getCMSFields();
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
- $fields->replaceField('Default', CheckboxField::create(
- "CheckedDefault",
- _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
- ));
+ $fields->replaceField('Default', CheckboxField::create(
+ "CheckedDefault",
+ _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
+ ));
- return $fields;
- }
+ return $fields;
+ }
- public function getFormField() {
- $field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault)
- ->setFieldHolderTemplate('UserFormsCheckboxField_holder')
- ->setTemplate('UserFormsCheckboxField');
+ public function getFormField()
+ {
+ $field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault)
+ ->setFieldHolderTemplate('UserFormsCheckboxField_holder')
+ ->setTemplate('UserFormsCheckboxField');
- $this->doUpdateFormField($field);
+ $this->doUpdateFormField($field);
- return $field;
- }
+ return $field;
+ }
- public function getValueFromData($data) {
- $value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
+ public function getValueFromData($data)
+ {
+ $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) {
- // Migrate 'Default' setting to 'CheckedDefault'
- if(isset($data['Default'])) {
- $this->CheckedDefault = (bool)$data['Default'];
- unset($data['Default']);
- }
+ public function migrateSettings($data)
+ {
+ // Migrate 'Default' setting to 'CheckedDefault'
+ if (isset($data['Default'])) {
+ $this->CheckedDefault = (bool)$data['Default'];
+ unset($data['Default']);
+ }
- parent::migrateSettings($data);
- }
+ parent::migrateSettings($data);
+ }
}
diff --git a/code/model/editableformfields/EditableCheckboxGroupField.php b/code/model/editableformfields/EditableCheckboxGroupField.php
index 5832f27..f98faf3 100755
--- a/code/model/editableformfields/EditableCheckboxGroupField.php
+++ b/code/model/editableformfields/EditableCheckboxGroupField.php
@@ -7,52 +7,56 @@
* @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() {
- $field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
- $field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
+ public function getFormField()
+ {
+ $field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
+ $field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
- // Set the default checked items
- $defaultCheckedItems = $this->getDefaultOptions();
- if ($defaultCheckedItems->count()) {
- $field->setDefaultItems($defaultCheckedItems->map('EscapedTitle')->keys());
- }
+ // Set the default checked items
+ $defaultCheckedItems = $this->getDefaultOptions();
+ if ($defaultCheckedItems->count()) {
+ $field->setDefaultItems($defaultCheckedItems->map('EscapedTitle')->keys());
+ }
- $this->doUpdateFormField($field);
- return $field;
- }
+ $this->doUpdateFormField($field);
+ return $field;
+ }
- public function getValueFromData($data) {
- $result = '';
- $entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
+ public function getValueFromData($data)
+ {
+ $result = '';
+ $entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
- if($entries) {
- if(!is_array($data[$this->Name])) {
- $entries = array($data[$this->Name]);
- }
- foreach($entries as $selected => $value) {
- if(!$result) {
- $result = $value;
- } else {
- $result .= ", " . $value;
- }
- }
- }
- return $result;
- }
+ if ($entries) {
+ if (!is_array($data[$this->Name])) {
+ $entries = array($data[$this->Name]);
+ }
+ foreach ($entries as $selected => $value) {
+ if (!$result) {
+ $result = $value;
+ } else {
+ $result .= ", " . $value;
+ }
+ }
+ }
+ return $result;
+ }
- public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
- // watch out for checkboxs as the inputs don't have values but are 'checked
- // @todo - Test this
- if($rule->FieldValue) {
- return "$(\"input[name='{$this->Name}[]'][value='{$rule->FieldValue}']\")";
- } else {
- return "$(\"input[name='{$this->Name}[]']:first\")";
- }
- }
+ public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
+ {
+ // watch out for checkboxs as the inputs don't have values but are 'checked
+ // @todo - Test this
+ if ($rule->FieldValue) {
+ return "$(\"input[name='{$this->Name}[]'][value='{$rule->FieldValue}']\")";
+ } else {
+ return "$(\"input[name='{$this->Name}[]']:first\")";
+ }
+ }
}
diff --git a/code/model/editableformfields/EditableCountryDropdownField.php b/code/model/editableformfields/EditableCountryDropdownField.php
index fa8f5ae..7be2d1e 100644
--- a/code/model/editableformfields/EditableCountryDropdownField.php
+++ b/code/model/editableformfields/EditableCountryDropdownField.php
@@ -5,45 +5,51 @@
*
* @package userforms
*/
-class EditableCountryDropdownField extends EditableFormField {
+class EditableCountryDropdownField extends EditableFormField
+{
- private static $singular_name = 'Country Dropdown';
+ private static $singular_name = 'Country Dropdown';
- private static $plural_name = 'Country Dropdowns';
+ private static $plural_name = 'Country Dropdowns';
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- $fields = parent::getCMSFields();
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
- $fields->removeByName('Default');
+ $fields->removeByName('Default');
- return $fields;
- }
+ return $fields;
+ }
- public function getFormField() {
- $field = CountryDropdownField::create($this->Name, $this->EscapedTitle)
- ->setFieldHolderTemplate('UserFormsField_holder')
- ->setTemplate('UserFormsDropdownField');
+ public function getFormField()
+ {
+ $field = CountryDropdownField::create($this->Name, $this->EscapedTitle)
+ ->setFieldHolderTemplate('UserFormsField_holder')
+ ->setTemplate('UserFormsDropdownField');
- $this->doUpdateFormField($field);
+ $this->doUpdateFormField($field);
- return $field;
- }
+ return $field;
+ }
- public function getValueFromData($data) {
- if(isset($data[$this->Name])) {
- $source = $this->getFormField()->getSource();
- return $source[$data[$this->Name]];
- }
- }
+ public function getValueFromData($data)
+ {
+ if (isset($data[$this->Name])) {
+ $source = $this->getFormField()->getSource();
+ return $source[$data[$this->Name]];
+ }
+ }
- public function getIcon() {
- return USERFORMS_DIR . '/images/editabledropdown.png';
- }
+ public function getIcon()
+ {
+ return USERFORMS_DIR . '/images/editabledropdown.png';
+ }
- public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
- return "$(\"select[name='{$this->Name}']\")";
- }
-}
\ No newline at end of file
+ public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
+ {
+ return "$(\"select[name='{$this->Name}']\")";
+ }
+}
diff --git a/code/model/editableformfields/EditableDateField.php b/code/model/editableformfields/EditableDateField.php
index c91367b..676695e 100755
--- a/code/model/editableformfields/EditableDateField.php
+++ b/code/model/editableformfields/EditableDateField.php
@@ -7,60 +7,65 @@
* @package userforms
*/
-class EditableDateField extends EditableFormField {
+class EditableDateField extends EditableFormField
+{
- private static $singular_name = 'Date Field';
+ private static $singular_name = 'Date Field';
- private static $plural_name = 'Date Fields';
+ private static $plural_name = 'Date Fields';
- private static $db = array(
- 'DefaultToToday' => 'Boolean' // From customsettings
- );
+ private static $db = array(
+ 'DefaultToToday' => 'Boolean' // From customsettings
+ );
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- $this->beforeUpdateCMSFields(function(FieldList $fields) {
- $fields->addFieldToTab(
- 'Root.Main',
- CheckboxField::create(
- 'DefaultToToday',
- _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?')
- ),
- 'RightTitle'
- );
- });
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $this->beforeUpdateCMSFields(function (FieldList $fields) {
+ $fields->addFieldToTab(
+ 'Root.Main',
+ CheckboxField::create(
+ 'DefaultToToday',
+ _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?')
+ ),
+ 'RightTitle'
+ );
+ });
- return parent::getCMSFields();
- }
+ return parent::getCMSFields();
+ }
- /**
- * Return the form field
- *
- */
- public function getFormField() {
- $defaultValue = $this->DefaultToToday
- ? SS_Datetime::now()->Format('Y-m-d')
- : $this->Default;
+ /**
+ * Return the form field
+ *
+ */
+ public function getFormField()
+ {
+ $defaultValue = $this->DefaultToToday
+ ? SS_Datetime::now()->Format('Y-m-d')
+ : $this->Default;
- $field = EditableDateField_FormField::create( $this->Name, $this->EscapedTitle, $defaultValue)
- ->setConfig('showcalendar', true)
- ->setFieldHolderTemplate('UserFormsField_holder')
- ->setTemplate('UserFormsField');
+ $field = EditableDateField_FormField::create($this->Name, $this->EscapedTitle, $defaultValue)
+ ->setConfig('showcalendar', true)
+ ->setFieldHolderTemplate('UserFormsField_holder')
+ ->setTemplate('UserFormsField');
- $this->doUpdateFormField($field);
+ $this->doUpdateFormField($field);
- return $field;
- }
+ return $field;
+ }
}
/**
* @package userforms
*/
-class EditableDateField_FormField extends DateField {
+class EditableDateField_FormField extends DateField
+{
- public function Type() {
- return "date-alt text";
- }
-}
\ No newline at end of file
+ public function Type()
+ {
+ return "date-alt text";
+ }
+}
diff --git a/code/model/editableformfields/EditableDropdown.php b/code/model/editableformfields/EditableDropdown.php
index ff52761..a576c1a 100755
--- a/code/model/editableformfields/EditableDropdown.php
+++ b/code/model/editableformfields/EditableDropdown.php
@@ -7,41 +7,45 @@
* @package userforms
*/
-class EditableDropdown extends EditableMultipleOptionField {
+class EditableDropdown extends EditableMultipleOptionField
+{
- private static $singular_name = 'Dropdown Field';
+ private static $singular_name = 'Dropdown Field';
- private static $plural_name = 'Dropdowns';
+ private static $plural_name = 'Dropdowns';
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- $fields = parent::getCMSFields();
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
- $fields->removeByName('Default');
+ $fields->removeByName('Default');
- return $fields;
- }
+ return $fields;
+ }
- /**
- * @return DropdownField
- */
- public function getFormField() {
- $field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap())
- ->setFieldHolderTemplate('UserFormsField_holder')
- ->setTemplate('UserFormsDropdownField');
+ /**
+ * @return DropdownField
+ */
+ public function getFormField()
+ {
+ $field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap())
+ ->setFieldHolderTemplate('UserFormsField_holder')
+ ->setTemplate('UserFormsDropdownField');
- // Set default
- $defaultOption = $this->getDefaultOptions()->first();
- if($defaultOption) {
- $field->setValue($defaultOption->EscapedTitle);
- }
- $this->doUpdateFormField($field);
- return $field;
- }
+ // Set default
+ $defaultOption = $this->getDefaultOptions()->first();
+ if ($defaultOption) {
+ $field->setValue($defaultOption->EscapedTitle);
+ }
+ $this->doUpdateFormField($field);
+ return $field;
+ }
- public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
- return "$(\"select[name='{$this->Name}']\")";
- }
-}
\ No newline at end of file
+ public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
+ {
+ return "$(\"select[name='{$this->Name}']\")";
+ }
+}
diff --git a/code/model/editableformfields/EditableEmailField.php b/code/model/editableformfields/EditableEmailField.php
index 17590ba..7bf0446 100755
--- a/code/model/editableformfields/EditableEmailField.php
+++ b/code/model/editableformfields/EditableEmailField.php
@@ -7,56 +7,61 @@
* @package userforms
*/
-class EditableEmailField extends EditableFormField {
+class EditableEmailField extends EditableFormField
+{
- private static $singular_name = 'Email Field';
+ private static $singular_name = 'Email Field';
- private static $plural_name = 'Email Fields';
+ private static $plural_name = 'Email Fields';
- private static $db = array(
- 'Placeholder' => 'Varchar(255)'
- );
+ private static $db = array(
+ 'Placeholder' => 'Varchar(255)'
+ );
- public function getCMSFields() {
- $this->beforeUpdateCMSFields(function($fields) {
- $fields->addFieldToTab(
- 'Root.Main',
- TextField::create(
- 'Placeholder',
- _t('EditableTextField.PLACEHOLDER', 'Placeholder')
- )
- );
- });
+ public function getCMSFields()
+ {
+ $this->beforeUpdateCMSFields(function ($fields) {
+ $fields->addFieldToTab(
+ 'Root.Main',
+ TextField::create(
+ 'Placeholder',
+ _t('EditableTextField.PLACEHOLDER', 'Placeholder')
+ )
+ );
+ });
- return parent::getCMSFields();
- }
+ return parent::getCMSFields();
+ }
- public function getSetsOwnError() {
- return true;
- }
+ public function getSetsOwnError()
+ {
+ return true;
+ }
- public function getFormField() {
- $field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default)
- ->setFieldHolderTemplate('UserFormsField_holder')
- ->setTemplate('UserFormsField');
+ public function getFormField()
+ {
+ $field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default)
+ ->setFieldHolderTemplate('UserFormsField_holder')
+ ->setTemplate('UserFormsField');
- $this->doUpdateFormField($field);
+ $this->doUpdateFormField($field);
- return $field;
- }
+ return $field;
+ }
- /**
- * Updates a formfield with the additional metadata specified by this field
- *
- * @param FormField $field
- */
- protected function updateFormField($field) {
- parent::updateFormField($field);
+ /**
+ * Updates a formfield with the additional metadata specified by this field
+ *
+ * @param FormField $field
+ */
+ protected function updateFormField($field)
+ {
+ parent::updateFormField($field);
- $field->setAttribute('data-rule-email', true);
+ $field->setAttribute('data-rule-email', true);
- if($this->Placeholder) {
- $field->setAttribute('placeholder', $this->Placeholder);
- }
- }
-}
\ No newline at end of file
+ if ($this->Placeholder) {
+ $field->setAttribute('placeholder', $this->Placeholder);
+ }
+ }
+}
diff --git a/code/model/editableformfields/EditableFieldGroup.php b/code/model/editableformfields/EditableFieldGroup.php
index 5c91743..603b371 100644
--- a/code/model/editableformfields/EditableFieldGroup.php
+++ b/code/model/editableformfields/EditableFieldGroup.php
@@ -3,90 +3,98 @@
/**
* Specifies that this ends a group of fields
*/
-class EditableFieldGroup extends EditableFormField {
+class EditableFieldGroup extends EditableFormField
+{
- private static $has_one = array(
- 'End' => 'EditableFieldGroupEnd'
- );
+ private static $has_one = array(
+ 'End' => 'EditableFieldGroupEnd'
+ );
- /**
- * Disable selection of group class
- *
- * @config
- * @var bool
- */
- private static $hidden = true;
+ /**
+ * Disable selection of group class
+ *
+ * @config
+ * @var bool
+ */
+ private static $hidden = true;
- /**
- * Non-data field type
- *
- * @var type
- */
- private static $literal = true;
+ /**
+ * Non-data field type
+ *
+ * @var type
+ */
+ private static $literal = true;
- public function getCMSFields() {
- $fields = parent::getCMSFields();
- $fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
- return $fields;
- }
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
+ $fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
+ return $fields;
+ }
- public function getCMSTitle() {
- $title = $this->getFieldNumber()
- ?: $this->Title
- ?: 'group';
+ public function getCMSTitle()
+ {
+ $title = $this->getFieldNumber()
+ ?: $this->Title
+ ?: 'group';
- return _t(
- 'EditableFieldGroupEnd.FIELD_GROUP_START',
- 'Group {group}',
- array(
- 'group' => $title
- )
- );
- }
+ return _t(
+ 'EditableFieldGroupEnd.FIELD_GROUP_START',
+ 'Group {group}',
+ array(
+ 'group' => $title
+ )
+ );
+ }
- public function getInlineClassnameField($column, $fieldClasses) {
- return new LabelField($column, $this->CMSTitle);
- }
+ public function getInlineClassnameField($column, $fieldClasses)
+ {
+ return new LabelField($column, $this->CMSTitle);
+ }
- public function showInReports() {
- return false;
- }
+ public function showInReports()
+ {
+ return false;
+ }
- public function getFormField() {
- $field = UserFormsGroupField::create()
- ->setTitle($this->EscapedTitle ?: false)
- ->setName($this->Name);
- $this->doUpdateFormField($field);
- return $field;
- }
+ public function getFormField()
+ {
+ $field = UserFormsGroupField::create()
+ ->setTitle($this->EscapedTitle ?: false)
+ ->setName($this->Name);
+ $this->doUpdateFormField($field);
+ return $field;
+ }
- protected function updateFormField($field) {
- // set the right title on this field
- if($this->RightTitle) {
- // Since this field expects raw html, safely escape the user data prior
- $field->setRightTitle(Convert::raw2xml($this->RightTitle));
- }
+ protected function updateFormField($field)
+ {
+ // set the right title on this field
+ if ($this->RightTitle) {
+ // Since this field expects raw html, safely escape the user data prior
+ $field->setRightTitle(Convert::raw2xml($this->RightTitle));
+ }
- // if this field has an extra class
- if($this->ExtraClass) {
- $field->addExtraClass($this->ExtraClass);
- }
- }
+ // if this field has an extra class
+ if ($this->ExtraClass) {
+ $field->addExtraClass($this->ExtraClass);
+ }
+ }
- protected function onBeforeDelete() {
- parent::onBeforeDelete();
+ protected function onBeforeDelete()
+ {
+ parent::onBeforeDelete();
- // Ensures EndID is lazy-loaded for onAfterDelete
- $this->EndID;
- }
+ // Ensures EndID is lazy-loaded for onAfterDelete
+ $this->EndID;
+ }
- protected function onAfterDelete() {
- parent::onAfterDelete();
-
- // Delete end
- if(($end = $this->End()) && $end->exists()) {
- $end->delete();
- }
- }
+ protected function onAfterDelete()
+ {
+ parent::onAfterDelete();
+ // Delete end
+ if (($end = $this->End()) && $end->exists()) {
+ $end->delete();
+ }
+ }
}
diff --git a/code/model/editableformfields/EditableFieldGroupEnd.php b/code/model/editableformfields/EditableFieldGroupEnd.php
index 3bfb1ee..d469a84 100644
--- a/code/model/editableformfields/EditableFieldGroupEnd.php
+++ b/code/model/editableformfields/EditableFieldGroupEnd.php
@@ -3,92 +3,100 @@
/**
* Specifies that this ends a group of fields
*/
-class EditableFieldGroupEnd extends EditableFormField {
+class EditableFieldGroupEnd extends EditableFormField
+{
- private static $belongs_to = array(
- 'Group' => 'EditableFieldGroup'
- );
+ private static $belongs_to = array(
+ 'Group' => 'EditableFieldGroup'
+ );
- /**
- * Disable selection of group class
- *
- * @config
- * @var bool
- */
- private static $hidden = true;
+ /**
+ * Disable selection of group class
+ *
+ * @config
+ * @var bool
+ */
+ private static $hidden = true;
- /**
- * Non-data type
- *
- * @config
- * @var bool
- */
- private static $literal = true;
+ /**
+ * Non-data type
+ *
+ * @config
+ * @var bool
+ */
+ private static $literal = true;
- public function getCMSTitle() {
- $group = $this->Group();
- return _t(
- 'EditableFieldGroupEnd.FIELD_GROUP_END',
- '{group} end',
- array(
- 'group' => ($group && $group->exists()) ? $group->CMSTitle : 'Group'
- )
- );
- }
+ public function getCMSTitle()
+ {
+ $group = $this->Group();
+ return _t(
+ 'EditableFieldGroupEnd.FIELD_GROUP_END',
+ '{group} end',
+ array(
+ 'group' => ($group && $group->exists()) ? $group->CMSTitle : 'Group'
+ )
+ );
+ }
- public function getCMSFields() {
- $fields = parent::getCMSFields();
- $fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
- return $fields;
- }
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
+ $fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
+ return $fields;
+ }
- public function getInlineClassnameField($column, $fieldClasses) {
- return new LabelField($column, $this->CMSTitle);
- }
+ public function getInlineClassnameField($column, $fieldClasses)
+ {
+ return new LabelField($column, $this->CMSTitle);
+ }
- public function getInlineTitleField($column) {
- return HiddenField::create($column);
- }
+ public function getInlineTitleField($column)
+ {
+ return HiddenField::create($column);
+ }
- public function getFormField() {
- return null;
- }
+ public function getFormField()
+ {
+ return null;
+ }
- public function showInReports() {
- return false;
- }
+ public function showInReports()
+ {
+ return false;
+ }
- public function onAfterWrite() {
- parent::onAfterWrite();
+ public function onAfterWrite()
+ {
+ parent::onAfterWrite();
- // If this is not attached to a group, find the first group prior to this
- // with no end attached
- $group = $this->Group();
- if(!($group && $group->exists()) && $this->ParentID) {
- $group = EditableFieldGroup::get()
- ->filter(array(
- 'ParentID' => $this->ParentID,
- 'Sort:LessThanOrEqual' => $this->Sort
- ))
- ->where('"EditableFieldGroup"."EndID" IS NULL OR "EditableFieldGroup"."EndID" = 0')
- ->sort('"Sort" DESC')
- ->first();
+ // If this is not attached to a group, find the first group prior to this
+ // with no end attached
+ $group = $this->Group();
+ if (!($group && $group->exists()) && $this->ParentID) {
+ $group = EditableFieldGroup::get()
+ ->filter(array(
+ 'ParentID' => $this->ParentID,
+ 'Sort:LessThanOrEqual' => $this->Sort
+ ))
+ ->where('"EditableFieldGroup"."EndID" IS NULL OR "EditableFieldGroup"."EndID" = 0')
+ ->sort('"Sort" DESC')
+ ->first();
- // When a group is found, attach it to this end
- if($group) {
- $group->EndID = $this->ID;
- $group->write();
- }
- }
- }
+ // When a group is found, attach it to this end
+ if ($group) {
+ $group->EndID = $this->ID;
+ $group->write();
+ }
+ }
+ }
- protected function onAfterDelete() {
- parent::onAfterDelete();
-
- // Delete group
- if(($group = $this->Group()) && $group->exists()) {
- $group->delete();
- }
- }
+ protected function onAfterDelete()
+ {
+ parent::onAfterDelete();
+ // Delete group
+ if (($group = $this->Group()) && $group->exists()) {
+ $group->delete();
+ }
+ }
}
diff --git a/code/model/editableformfields/EditableFileField.php b/code/model/editableformfields/EditableFileField.php
index 37fa70d..a66064e 100755
--- a/code/model/editableformfields/EditableFileField.php
+++ b/code/model/editableformfields/EditableFileField.php
@@ -6,99 +6,105 @@
* @package userforms
*/
-class EditableFileField extends EditableFormField {
+class EditableFileField extends EditableFormField
+{
- private static $singular_name = 'File Upload Field';
+ private static $singular_name = 'File Upload Field';
- private static $plural_names = 'File Fields';
+ private static $plural_names = 'File Fields';
- private static $has_one = array(
- 'Folder' => 'Folder' // From CustomFields
- );
+ private static $has_one = array(
+ 'Folder' => 'Folder' // From CustomFields
+ );
- /**
- * Further limit uploadable file extensions in addition to the restrictions
- * imposed by the File.allowed_extensions global configuration.
- * @config
- */
- private static $allowed_extensions_blacklist = array(
- 'htm', 'html', 'xhtml', 'swf', 'xml'
- );
+ /**
+ * Further limit uploadable file extensions in addition to the restrictions
+ * imposed by the File.allowed_extensions global configuration.
+ * @config
+ */
+ private static $allowed_extensions_blacklist = array(
+ 'htm', 'html', 'xhtml', 'swf', 'xml'
+ );
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- $fields = parent::getCMSFields();
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $fields = parent::getCMSFields();
- $fields->addFieldToTab(
- 'Root.Main',
- TreeDropdownField::create(
- 'FolderID',
- _t('EditableUploadField.SELECTUPLOADFOLDER', 'Select upload folder'),
- 'Folder'
- )
- );
+ $fields->addFieldToTab(
+ 'Root.Main',
+ TreeDropdownField::create(
+ 'FolderID',
+ _t('EditableUploadField.SELECTUPLOADFOLDER', 'Select upload folder'),
+ 'Folder'
+ )
+ );
- $fields->addFieldToTab("Root.Main", new LiteralField("FileUploadWarning",
- "
" . _t("UserDefinedForm.FileUploadWarning",
- "Files uploaded through this field could be publicly accessible if the exact URL is known")
- . "
"), "Type");
+ $fields->addFieldToTab("Root.Main", new LiteralField("FileUploadWarning",
+ "
" . _t("UserDefinedForm.FileUploadWarning",
+ "Files uploaded through this field could be publicly accessible if the exact URL is known")
+ . "
"), "Type");
- return $fields;
- }
+ return $fields;
+ }
- public function getFormField() {
+ public function getFormField()
+ {
$field = FileField::create($this->Name, $this->EscapedTitle)
- ->setFieldHolderTemplate('UserFormsField_holder')
- ->setTemplate('UserFormsFileField');
+ ->setFieldHolderTemplate('UserFormsField_holder')
+ ->setTemplate('UserFormsFileField');
- $field->setFieldHolderTemplate('UserFormsField_holder')
- ->setTemplate('UserFormsFileField');
+ $field->setFieldHolderTemplate('UserFormsField_holder')
+ ->setTemplate('UserFormsFileField');
- $field->getValidator()->setAllowedExtensions(
- array_diff(
- // filter out '' since this would be a regex problem on JS end
- array_filter(Config::inst()->get('File', 'allowed_extensions')),
- $this->config()->allowed_extensions_blacklist
- )
- );
+ $field->getValidator()->setAllowedExtensions(
+ array_diff(
+ // filter out '' since this would be a regex problem on JS end
+ array_filter(Config::inst()->get('File', 'allowed_extensions')),
+ $this->config()->allowed_extensions_blacklist
+ )
+ );
- $folder = $this->Folder();
- if($folder && $folder->exists()) {
- $field->setFolderName(
- preg_replace("/^assets\//","", $folder->Filename)
- );
- }
+ $folder = $this->Folder();
+ if ($folder && $folder->exists()) {
+ $field->setFolderName(
+ preg_replace("/^assets\//", "", $folder->Filename)
+ );
+ }
- $this->doUpdateFormField($field);
+ $this->doUpdateFormField($field);
- return $field;
- }
+ return $field;
+ }
- /**
- * Return the value for the database, link to the file is stored as a
- * relation so value for the field can be null.
- *
- * @return string
- */
- public function getValueFromData() {
- return null;
- }
+ /**
+ * Return the value for the database, link to the file is stored as a
+ * relation so value for the field can be null.
+ *
+ * @return string
+ */
+ public function getValueFromData()
+ {
+ return null;
+ }
- public function getSubmittedFormField() {
- return new SubmittedFileField();
- }
+ public function getSubmittedFormField()
+ {
+ return new SubmittedFileField();
+ }
- public function migrateSettings($data) {
- // Migrate 'Folder' setting to 'FolderID'
- if(isset($data['Folder'])) {
- $this->FolderID = $data['Folder'];
- unset($data['Folder']);
- }
+ public function migrateSettings($data)
+ {
+ // Migrate 'Folder' setting to 'FolderID'
+ if (isset($data['Folder'])) {
+ $this->FolderID = $data['Folder'];
+ unset($data['Folder']);
+ }
- parent::migrateSettings($data);
- }
+ parent::migrateSettings($data);
+ }
}
diff --git a/code/model/editableformfields/EditableFormField.php b/code/model/editableformfields/EditableFormField.php
index 1ddcca0..c1574f1 100755
--- a/code/model/editableformfields/EditableFormField.php
+++ b/code/model/editableformfields/EditableFormField.php
@@ -17,380 +17,387 @@ use SilverStripe\Forms\SegmentField;
* @method UserDefinedForm Parent() Parent page
* @method DataList DisplayRules() List of EditableCustomRule objects
*/
-class EditableFormField extends DataObject {
+class EditableFormField extends DataObject
+{
- /**
- * Set to true to hide from class selector
- *
- * @config
- * @var bool
- */
- private static $hidden = false;
+ /**
+ * Set to true to hide from class selector
+ *
+ * @config
+ * @var bool
+ */
+ private static $hidden = false;
- /**
- * Define this field as abstract (not inherited)
- *
- * @config
- * @var bool
- */
- private static $abstract = true;
+ /**
+ * Define this field as abstract (not inherited)
+ *
+ * @config
+ * @var bool
+ */
+ private static $abstract = true;
- /**
- * Flag this field type as non-data (e.g. literal, header, html)
- *
- * @config
- * @var bool
- */
- private static $literal = false;
+ /**
+ * Flag this field type as non-data (e.g. literal, header, html)
+ *
+ * @config
+ * @var bool
+ */
+ private static $literal = false;
- /**
- * Default sort order
- *
- * @config
- * @var string
- */
- private static $default_sort = '"Sort"';
+ /**
+ * Default sort order
+ *
+ * @config
+ * @var string
+ */
+ private static $default_sort = '"Sort"';
- /**
- * A list of CSS classes that can be added
- *
- * @var array
- */
- public static $allowed_css = array();
+ /**
+ * A list of CSS classes that can be added
+ *
+ * @var array
+ */
+ public static $allowed_css = array();
- /**
- * @config
- * @var array
- */
- private static $summary_fields = array(
- 'Title'
- );
+ /**
+ * @config
+ * @var array
+ */
+ private static $summary_fields = array(
+ 'Title'
+ );
- /**
- * @config
- * @var array
- */
- private static $db = array(
- "Name" => "Varchar",
- "Title" => "Varchar(255)",
- "Default" => "Varchar(255)",
- "Sort" => "Int",
- "Required" => "Boolean",
- "CustomErrorMessage" => "Varchar(255)",
+ /**
+ * @config
+ * @var array
+ */
+ private static $db = array(
+ "Name" => "Varchar",
+ "Title" => "Varchar(255)",
+ "Default" => "Varchar(255)",
+ "Sort" => "Int",
+ "Required" => "Boolean",
+ "CustomErrorMessage" => "Varchar(255)",
- "CustomRules" => "Text", // @deprecated from 2.0
- "CustomSettings" => "Text", // @deprecated from 2.0
- "Migrated" => "Boolean", // set to true when migrated
+ "CustomRules" => "Text", // @deprecated from 2.0
+ "CustomSettings" => "Text", // @deprecated from 2.0
+ "Migrated" => "Boolean", // set to true when migrated
- "ExtraClass" => "Text", // from CustomSettings
- "RightTitle" => "Varchar(255)", // from CustomSettings
- "ShowOnLoad" => "Boolean(1)", // from CustomSettings
- );
-
- private static $defaults = array(
- 'ShowOnLoad' => true,
- );
+ "ExtraClass" => "Text", // from CustomSettings
+ "RightTitle" => "Varchar(255)", // from CustomSettings
+ "ShowOnLoad" => "Boolean(1)", // from CustomSettings
+ );
+
+ private static $defaults = array(
+ 'ShowOnLoad' => true,
+ );
- /**
- * @config
- * @var array
- */
- private static $has_one = array(
- "Parent" => "UserDefinedForm",
- );
+ /**
+ * @config
+ * @var array
+ */
+ private static $has_one = array(
+ "Parent" => "UserDefinedForm",
+ );
- /**
- * Built in extensions required
- *
- * @config
- * @var array
- */
- private static $extensions = array(
- "Versioned('Stage', 'Live')"
- );
+ /**
+ * Built in extensions required
+ *
+ * @config
+ * @var array
+ */
+ private static $extensions = array(
+ "Versioned('Stage', 'Live')"
+ );
- /**
- * @config
- * @var array
- */
- private static $has_many = array(
- "DisplayRules" => "EditableCustomRule.Parent" // from CustomRules
- );
+ /**
+ * @config
+ * @var array
+ */
+ private static $has_many = array(
+ "DisplayRules" => "EditableCustomRule.Parent" // from CustomRules
+ );
- /**
- * @var bool
- */
- protected $readonly;
+ /**
+ * @var bool
+ */
+ protected $readonly;
- /**
- * Set the visibility of an individual form field
- *
- * @param bool
- */
- public function setReadonly($readonly = true) {
- $this->readonly = $readonly;
- }
+ /**
+ * Set the visibility of an individual form field
+ *
+ * @param bool
+ */
+ public function setReadonly($readonly = true)
+ {
+ $this->readonly = $readonly;
+ }
- /**
- * Returns whether this field is readonly
- *
- * @return bool
- */
- private function isReadonly() {
- return $this->readonly;
- }
+ /**
+ * Returns whether this field is readonly
+ *
+ * @return bool
+ */
+ private function isReadonly()
+ {
+ return $this->readonly;
+ }
- /**
- * @return FieldList
- */
- public function getCMSFields() {
- $fields = new FieldList(new TabSet('Root'));
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $fields = new FieldList(new TabSet('Root'));
- // Main tab
- $fields->addFieldsToTab(
- 'Root.Main',
- array(
- ReadonlyField::create(
- 'Type',
- _t('EditableFormField.TYPE', 'Type'),
- $this->i18n_singular_name()
- ),
- LiteralField::create(
- 'MergeField',
- _t(
- 'EditableFormField.MERGEFIELDNAME',
- '
%s',
+ "admin/pages/edit/EditForm/field/EmailRecipients/item/{$this->ID}/preview",
+ _t('UserDefinedForm.PREVIEW_EMAIL', 'Preview email'),
+ _t('UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION', 'Note: Unsaved changes will not appear in the preview.')
+ );
+ } else {
+ $preview = sprintf(
+ '%s',
+ _t(
+ 'UserDefinedForm.PREVIEW_EMAIL_UNAVAILABLE',
+ 'You can preview this email once you have saved the Recipient.'
+ )
+ );
+ }
- // Only show the preview link if the recipient has been saved.
- if (!empty($this->EmailTemplate)) {
- $preview = sprintf(
- '
'
- )
- ));
+ // Custom rules for sending this field
+ $grid = new GridField(
+ "CustomRules",
+ _t('EditableFormField.CUSTOMRULES', 'Custom Rules'),
+ $this->CustomRules(),
+ $this->getRulesConfig()
+ );
+ $grid->setDescription(_t(
+ 'UserDefinedForm.RulesDescription',
+ 'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, this receipient will receive notifications for every submission.'
+ ));
+ $fields->addFieldsToTab('Root.CustomRules', array(
+ new DropdownField(
+ 'CustomRulesCondition',
+ _t('UserDefinedForm.SENDIF', 'Send condition'),
+ array(
+ 'Or' => _t('UserDefinedForm.SENDIFOR', 'Any conditions are true'),
+ 'And' => _t('UserDefinedForm.SENDIFAND', 'All conditions are true')
+ )
+ ),
+ $grid
+ ));
+
+ $fields->fieldByName('Root.CustomRules')->setTitle(_t('UserDefinedForm_EmailRecipient.CUSTOMRULESTAB', 'Custom Rules'));
- $fields->fieldByName('Root.EmailContent')->setTitle(_t('UserDefinedForm_EmailRecipient.EMAILCONTENTTAB', 'Email Content'));
+ $this->extend('updateCMSFields', $fields);
+ return $fields;
+ }
- // Custom rules for sending this field
- $grid = new GridField(
- "CustomRules",
- _t('EditableFormField.CUSTOMRULES', 'Custom Rules'),
- $this->CustomRules(),
- $this->getRulesConfig()
- );
- $grid->setDescription(_t(
- 'UserDefinedForm.RulesDescription',
- 'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, this receipient will receive notifications for every submission.'
- ));
- $fields->addFieldsToTab('Root.CustomRules', array(
- new DropdownField(
- 'CustomRulesCondition',
- _t('UserDefinedForm.SENDIF', 'Send condition'),
- array(
- 'Or' => _t('UserDefinedForm.SENDIFOR', 'Any conditions are true'),
- 'And' => _t('UserDefinedForm.SENDIFAND', 'All conditions are true')
- )
- ),
- $grid
- ));
-
- $fields->fieldByName('Root.CustomRules')->setTitle(_t('UserDefinedForm_EmailRecipient.CUSTOMRULESTAB', 'Custom Rules'));
-
- $this->extend('updateCMSFields', $fields);
- return $fields;
- }
-
- /**
- * Return whether a user can create an object of this type
- *
+ /**
+ * Return whether a user can create an object of this type
+ *
* @param Member $member
* @param array $context Virtual parameter to allow context to be passed in to check
- * @return bool
- */
- public function canCreate($member = null) {
- // Check parent page
+ * @return bool
+ */
+ public function canCreate($member = null)
+ {
+ // Check parent page
$parent = $this->getCanCreateContext(func_get_args());
- if($parent) {
+ if ($parent) {
return $parent->canEdit($member);
}
// Fall back to secure admin permissions
return parent::canCreate($member);
- }
+ }
/**
* Helper method to check the parent for this object
@@ -313,13 +320,14 @@ class UserDefinedForm_EmailRecipient extends DataObject {
* @param array $args List of arguments passed to canCreate
* @return SiteTree Parent page instance
*/
- protected function getCanCreateContext($args) {
+ protected function getCanCreateContext($args)
+ {
// Inspect second parameter to canCreate for a 'Parent' context
- if(isset($args[1]['Form'])) {
+ if (isset($args[1]['Form'])) {
return $args[1]['Form'];
}
// 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();
}
@@ -327,104 +335,111 @@ class UserDefinedForm_EmailRecipient extends DataObject {
return null;
}
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canView($member = null) {
- return $this->Form()->canView($member);
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canView($member = null)
+ {
+ return $this->Form()->canView($member);
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canEdit($member = null) {
- return $this->Form()->canEdit($member);
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canEdit($member = null)
+ {
+ return $this->Form()->canEdit($member);
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canDelete($member = null) {
- return $this->canEdit($member);
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canDelete($member = null)
+ {
+ return $this->canEdit($member);
+ }
- /*
- * Determine if this recipient may receive notifications for this submission
- *
- * @param array $data
- * @param Form $form
- * @return bool
- */
- public function canSend($data, $form) {
- // Skip if no rules configured
- $customRules = $this->CustomRules();
- if(!$customRules->count()) {
- return true;
- }
+ /*
+ * Determine if this recipient may receive notifications for this submission
+ *
+ * @param array $data
+ * @param Form $form
+ * @return bool
+ */
+ public function canSend($data, $form)
+ {
+ // Skip if no rules configured
+ $customRules = $this->CustomRules();
+ if (!$customRules->count()) {
+ return true;
+ }
- // Check all rules
- $isAnd = $this->CustomRulesCondition === 'And';
- foreach($customRules as $customRule) {
- $matches = $customRule->matches($data, $form);
- if($isAnd && !$matches) {
- return false;
- }
- if(!$isAnd && $matches) {
- return true;
- }
- }
+ // Check all rules
+ $isAnd = $this->CustomRulesCondition === 'And';
+ foreach ($customRules as $customRule) {
+ $matches = $customRule->matches($data, $form);
+ if ($isAnd && !$matches) {
+ return false;
+ }
+ if (!$isAnd && $matches) {
+ return true;
+ }
+ }
- // Once all rules are checked
- return $isAnd;
- }
+ // Once all rules are checked
+ return $isAnd;
+ }
- /**
- * Make sure the email template saved against the recipient exists on the file system.
- *
- * @param string
- *
- * @return boolean
- */
- public function emailTemplateExists($template = '') {
- $t = ($template ? $template : $this->EmailTemplate);
+ /**
+ * Make sure the email template saved against the recipient exists on the file system.
+ *
+ * @param string
+ *
+ * @return boolean
+ */
+ public function emailTemplateExists($template = '')
+ {
+ $t = ($template ? $template : $this->EmailTemplate);
- return in_array($t, $this->getEmailTemplateDropdownValues());
- }
+ return in_array($t, $this->getEmailTemplateDropdownValues());
+ }
- /**
- * Get the email body for the current email format
- *
- * @return string
- */
- public function getEmailBodyContent() {
- return $this->SendPlain ? $this->EmailBody : $this->EmailBodyHtml;
- }
+ /**
+ * Get the email body for the current email format
+ *
+ * @return string
+ */
+ public function getEmailBodyContent()
+ {
+ return $this->SendPlain ? $this->EmailBody : $this->EmailBodyHtml;
+ }
- /**
- * Gets a list of email templates suitable for populating the email template dropdown.
- *
- * @return array
- */
- public function getEmailTemplateDropdownValues() {
- $templates = array();
+ /**
+ * Gets a list of email templates suitable for populating the email template dropdown.
+ *
+ * @return array
+ */
+ public function getEmailTemplateDropdownValues()
+ {
+ $templates = array();
- $finder = new SS_FileFinder();
- $finder->setOption('name_regex', '/^.*\.ss$/');
+ $finder = new SS_FileFinder();
+ $finder->setOption('name_regex', '/^.*\.ss$/');
- $found = $finder->find(BASE_PATH . '/' . UserDefinedForm::config()->email_template_directory);
+ $found = $finder->find(BASE_PATH . '/' . UserDefinedForm::config()->email_template_directory);
- foreach ($found as $key => $value) {
- $template = pathinfo($value);
+ foreach ($found as $key => $value) {
+ $template = pathinfo($value);
- $templates[$template['filename']] = $template['filename'];
- }
+ $templates[$template['filename']] = $template['filename'];
+ }
- return $templates;
- }
+ return $templates;
+ }
}
diff --git a/code/model/recipients/UserDefinedForm_EmailRecipientCondition.php b/code/model/recipients/UserDefinedForm_EmailRecipientCondition.php
index 424aae0..8617bc3 100644
--- a/code/model/recipients/UserDefinedForm_EmailRecipientCondition.php
+++ b/code/model/recipients/UserDefinedForm_EmailRecipientCondition.php
@@ -6,71 +6,74 @@
*
* @method UserDefinedForm_EmailRecipient Parent()
*/
-class UserDefinedForm_EmailRecipientCondition extends DataObject {
+class UserDefinedForm_EmailRecipientCondition extends DataObject
+{
- /**
- * List of options
- *
- * @config
- * @var array
- */
- private static $condition_options = array(
- "IsBlank" => "Is blank",
- "IsNotBlank" => "Is not blank",
- "Equals" => "Equals",
- "NotEquals" => "Doesn't equal"
- );
+ /**
+ * List of options
+ *
+ * @config
+ * @var array
+ */
+ private static $condition_options = array(
+ "IsBlank" => "Is blank",
+ "IsNotBlank" => "Is not blank",
+ "Equals" => "Equals",
+ "NotEquals" => "Doesn't equal"
+ );
- private static $db = array(
- 'ConditionOption' => 'Enum("IsBlank,IsNotBlank,Equals,NotEquals")',
- 'ConditionValue' => 'Varchar'
- );
+ private static $db = array(
+ 'ConditionOption' => 'Enum("IsBlank,IsNotBlank,Equals,NotEquals")',
+ 'ConditionValue' => 'Varchar'
+ );
- private static $has_one = array(
- 'Parent' => 'UserDefinedForm_EmailRecipient',
- 'ConditionField' => 'EditableFormField'
- );
+ private static $has_one = array(
+ 'Parent' => 'UserDefinedForm_EmailRecipient',
+ 'ConditionField' => 'EditableFormField'
+ );
- /**
- * Determine if this rule matches the given condition
- *
- * @param array $data
- * @param Form $form
- * @return bool
- */
- public function matches($data, $form) {
- $fieldName = $this->ConditionField()->Name;
- $fieldValue = isset($data[$fieldName]) ? $data[$fieldName] : null;
- switch($this->ConditionOption) {
- case 'IsBlank':
- return empty($fieldValue);
- case 'IsNotBlank':
- return !empty($fieldValue);
- default:
- $matches = is_array($fieldValue)
- ? in_array($this->ConditionValue, $fieldValue)
- : $this->ConditionValue === (string) $fieldValue;
- return ($this->ConditionOption === 'Equals') === (bool)$matches;
- }
- }
+ /**
+ * Determine if this rule matches the given condition
+ *
+ * @param array $data
+ * @param Form $form
+ * @return bool
+ */
+ public function matches($data, $form)
+ {
+ $fieldName = $this->ConditionField()->Name;
+ $fieldValue = isset($data[$fieldName]) ? $data[$fieldName] : null;
+ switch ($this->ConditionOption) {
+ case 'IsBlank':
+ return empty($fieldValue);
+ case 'IsNotBlank':
+ return !empty($fieldValue);
+ default:
+ $matches = is_array($fieldValue)
+ ? in_array($this->ConditionValue, $fieldValue)
+ : $this->ConditionValue === (string) $fieldValue;
+ return ($this->ConditionOption === 'Equals') === (bool)$matches;
+ }
+ }
- /**
- * Return whether a user can create an object of this type
- *
+ /**
+ * Return whether a user can create an object of this type
+ *
* @param Member $member
* @param array $context Virtual parameter to allow context to be passed in to check
- * @return bool
- */
- public function canCreate($member = null) {
- // Check parent page
+ * @return bool
+ */
+ public function canCreate($member = null)
+ {
+ // Check parent page
$parent = $this->getCanCreateContext(func_get_args());
- if($parent) {
+ if ($parent) {
return $parent->canEdit($member);
}
// Fall back to secure admin permissions
return parent::canCreate($member);
- }
+ }
/**
* Helper method to check the parent for this object
@@ -78,13 +81,14 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
* @param array $args List of arguments passed to canCreate
* @return SiteTree Parent page instance
*/
- protected function getCanCreateContext($args) {
+ protected function getCanCreateContext($args)
+ {
// Inspect second parameter to canCreate for a 'Parent' context
- if(isset($args[1]['Parent'])) {
+ if (isset($args[1]['Parent'])) {
return $args[1]['Parent'];
}
// 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();
}
@@ -92,30 +96,33 @@ class UserDefinedForm_EmailRecipientCondition extends DataObject {
return null;
}
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canView($member = null) {
- return $this->Parent()->canView($member);
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canView($member = null)
+ {
+ return $this->Parent()->canView($member);
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canEdit($member = null) {
- return $this->Parent()->canEdit($member);
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canEdit($member = null)
+ {
+ return $this->Parent()->canEdit($member);
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canDelete($member = null) {
- return $this->canEdit($member);
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canDelete($member = null)
+ {
+ return $this->canEdit($member);
+ }
}
diff --git a/code/model/recipients/UserFormRecipientEmail.php b/code/model/recipients/UserFormRecipientEmail.php
index 2d9bb2b..977eae0 100644
--- a/code/model/recipients/UserFormRecipientEmail.php
+++ b/code/model/recipients/UserFormRecipientEmail.php
@@ -8,23 +8,26 @@
* @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) {
- parent::__construct($submittedFields = null);
- }
+ public function __construct($submittedFields = null)
+ {
+ parent::__construct($submittedFields = null);
+ }
- /**
- * Set the "Reply-To" header with an email address rather than append as
- * {@link Email::replyTo} does.
- *
- * @param string $email The email address to set the "Reply-To" header to
- */
- public function setReplyTo($email) {
- $this->customHeaders['Reply-To'] = $email;
- }
+ /**
+ * Set the "Reply-To" header with an email address rather than append as
+ * {@link Email::replyTo} does.
+ *
+ * @param string $email The email address to set the "Reply-To" header to
+ */
+ public function setReplyTo($email)
+ {
+ $this->customHeaders['Reply-To'] = $email;
+ }
}
diff --git a/code/model/recipients/UserFormRecipientItemRequest.php b/code/model/recipients/UserFormRecipientItemRequest.php
index 7a03dc8..d0e4aa9 100644
--- a/code/model/recipients/UserFormRecipientItemRequest.php
+++ b/code/model/recipients/UserFormRecipientItemRequest.php
@@ -5,47 +5,50 @@
*
* @package userforms
*/
-class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest {
+class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
+{
- private static $allowed_actions = array(
- 'edit',
- 'view',
- 'ItemEditForm',
- 'preview'
- );
+ private static $allowed_actions = array(
+ 'edit',
+ 'view',
+ 'ItemEditForm',
+ 'preview'
+ );
- /**
- * Renders a preview of the recipient email.
- */
- public function preview() {
- return $this->customise(new ArrayData(array(
- 'Body' => $this->record->getEmailBodyContent(),
- 'HideFormData' => $this->record->HideFormData,
- 'Fields' => $this->getPreviewFieldData()
- )))->renderWith($this->record->EmailTemplate);
- }
+ /**
+ * Renders a preview of the recipient email.
+ */
+ public function preview()
+ {
+ return $this->customise(new ArrayData(array(
+ 'Body' => $this->record->getEmailBodyContent(),
+ 'HideFormData' => $this->record->HideFormData,
+ 'Fields' => $this->getPreviewFieldData()
+ )))->renderWith($this->record->EmailTemplate);
+ }
- /**
- * Get some placeholder field values to display in the preview
- * @return ArrayList
- */
- private function getPreviewFieldData() {
- $data = new ArrayList();
+ /**
+ * Get some placeholder field values to display in the preview
+ * @return ArrayList
+ */
+ private function getPreviewFieldData()
+ {
+ $data = new ArrayList();
- $fields = $this->record->Form()->Fields()->filter(array(
- 'ClassName:not' => 'EditableLiteralField',
- 'ClassName:not' => 'EditableFormHeading'
- ));
+ $fields = $this->record->Form()->Fields()->filter(array(
+ 'ClassName:not' => 'EditableLiteralField',
+ 'ClassName:not' => 'EditableFormHeading'
+ ));
- foreach ($fields as $field) {
- $data->push(new ArrayData(array(
- 'Name' => $field->Name,
- 'Title' => $field->Title,
- 'Value' => '$' . $field->Name,
- 'FormattedValue' => '$' . $field->Name
- )));
- }
+ foreach ($fields as $field) {
+ $data->push(new ArrayData(array(
+ 'Name' => $field->Name,
+ 'Title' => $field->Title,
+ 'Value' => '$' . $field->Name,
+ 'FormattedValue' => '$' . $field->Name
+ )));
+ }
- return $data;
- }
+ return $data;
+ }
}
diff --git a/code/model/submissions/SubmittedFileField.php b/code/model/submissions/SubmittedFileField.php
index 5a8fa47..557235a 100755
--- a/code/model/submissions/SubmittedFileField.php
+++ b/code/model/submissions/SubmittedFileField.php
@@ -7,63 +7,68 @@
* @package userforms
*/
-class SubmittedFileField extends SubmittedFormField {
+class SubmittedFileField extends SubmittedFormField
+{
- private static $has_one = array(
- "UploadedFile" => "File"
- );
+ private static $has_one = array(
+ "UploadedFile" => "File"
+ );
- /**
- * Return the value of this field for inclusion into things such as
- * reports.
- *
- * @return string
- */
- public function getFormattedValue() {
- $name = $this->getFileName();
- $link = $this->getLink();
- $title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
+ /**
+ * Return the value of this field for inclusion into things such as
+ * reports.
+ *
+ * @return string
+ */
+ public function getFormattedValue()
+ {
+ $name = $this->getFileName();
+ $link = $this->getLink();
+ $title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
- if($link) {
- return DBField::create_field('HTMLText', sprintf(
- '%s - %s',
- $name, $link, $title
- ));
- }
+ if ($link) {
+ return DBField::create_field('HTMLText', sprintf(
+ '%s - %s',
+ $name, $link, $title
+ ));
+ }
- return false;
- }
+ return false;
+ }
- /**
- * Return the value for this field in the CSV export.
- *
- * @return string
- */
- public function getExportValue() {
- return ($link = $this->getLink()) ? $link : "";
- }
+ /**
+ * Return the value for this field in the CSV export.
+ *
+ * @return string
+ */
+ public function getExportValue()
+ {
+ return ($link = $this->getLink()) ? $link : "";
+ }
- /**
- * Return the link for the file attached to this submitted form field.
- *
- * @return string
- */
- public function getLink() {
- if($file = $this->UploadedFile()) {
- if(trim($file->getFilename(), '/') != trim(ASSETS_DIR,'/')) {
- return $this->UploadedFile()->URL;
- }
- }
- }
+ /**
+ * Return the link for the file attached to this submitted form field.
+ *
+ * @return string
+ */
+ public function getLink()
+ {
+ if ($file = $this->UploadedFile()) {
+ if (trim($file->getFilename(), '/') != trim(ASSETS_DIR, '/')) {
+ return $this->UploadedFile()->URL;
+ }
+ }
+ }
- /**
- * Return the name of the file, if present
- *
- * @return string
- */
- public function getFileName() {
- if($this->UploadedFile()) {
- return $this->UploadedFile()->Name;
- }
- }
+ /**
+ * Return the name of the file, if present
+ *
+ * @return string
+ */
+ public function getFileName()
+ {
+ if ($this->UploadedFile()) {
+ return $this->UploadedFile()->Name;
+ }
+ }
}
diff --git a/code/model/submissions/SubmittedForm.php b/code/model/submissions/SubmittedForm.php
index 83cabcb..f026509 100755
--- a/code/model/submissions/SubmittedForm.php
+++ b/code/model/submissions/SubmittedForm.php
@@ -5,143 +5,150 @@
* @package userforms
*/
-class SubmittedForm extends DataObject {
+class SubmittedForm extends DataObject
+{
- private static $has_one = array(
- "SubmittedBy" => "Member",
- "Parent" => "UserDefinedForm",
- );
+ private static $has_one = array(
+ "SubmittedBy" => "Member",
+ "Parent" => "UserDefinedForm",
+ );
- private static $has_many = array(
- "Values" => "SubmittedFormField"
- );
+ private static $has_many = array(
+ "Values" => "SubmittedFormField"
+ );
- private static $summary_fields = array(
- 'ID',
- 'Created'
- );
+ private static $summary_fields = array(
+ 'ID',
+ 'Created'
+ );
- /**
- * Returns the value of a relation or, in the case of this form, the value
- * of a given child {@link SubmittedFormField}
- *
- * @param string
- *
- * @return mixed
- */
- public function relField($fieldName) {
- // default case
- if($value = parent::relField($fieldName)) {
- return $value;
- }
+ /**
+ * Returns the value of a relation or, in the case of this form, the value
+ * of a given child {@link SubmittedFormField}
+ *
+ * @param string
+ *
+ * @return mixed
+ */
+ public function relField($fieldName)
+ {
+ // default case
+ if ($value = parent::relField($fieldName)) {
+ return $value;
+ }
- // check values for a form field with the matching name.
- $formField = SubmittedFormField::get()->filter(array(
- 'ParentID' => $this->ID,
- 'Name' => $fieldName
- ))->first();
+ // check values for a form field with the matching name.
+ $formField = SubmittedFormField::get()->filter(array(
+ 'ParentID' => $this->ID,
+ 'Name' => $fieldName
+ ))->first();
- if($formField) {
- return $formField->getFormattedValue();
- }
- }
+ if ($formField) {
+ return $formField->getFormattedValue();
+ }
+ }
- /**
- * @return FieldList
- */
- public function getCMSFields() {
+ /**
+ * @return FieldList
+ */
+ public function getCMSFields()
+ {
+ $self = $this;
- $self = $this;
+ $this->beforeUpdateCMSFields(function ($fields) use ($self) {
+ $fields->removeByName('Values');
+ $fields->dataFieldByName('SubmittedByID')->setDisabled(true);
- $this->beforeUpdateCMSFields(function($fields) use ($self) {
- $fields->removeByName('Values');
- $fields->dataFieldByName('SubmittedByID')->setDisabled(true);
+ $values = new GridField(
+ 'Values',
+ 'SubmittedFormField',
+ $self->Values()->sort('Created', 'ASC')
+ );
- $values = new GridField(
- 'Values',
- 'SubmittedFormField',
- $self->Values()->sort('Created', 'ASC')
- );
+ $config = new GridFieldConfig();
+ $config->addComponent(new GridFieldDataColumns());
+ $config->addComponent(new GridFieldExportButton());
+ $config->addComponent(new GridFieldPrintButton());
+ $values->setConfig($config);
- $config = new GridFieldConfig();
- $config->addComponent(new GridFieldDataColumns());
- $config->addComponent(new GridFieldExportButton());
- $config->addComponent(new GridFieldPrintButton());
- $values->setConfig($config);
+ $fields->addFieldToTab('Root.Main', $values);
+ });
- $fields->addFieldToTab('Root.Main', $values);
- });
+ $fields = parent::getCMSFields();
- $fields = parent::getCMSFields();
+ return $fields;
+ }
- return $fields;
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canCreate($member = null)
+ {
+ $extended = $this->extendedCan(__FUNCTION__, $member);
+ if ($extended !== null) {
+ return $extended;
+ }
+ return $this->Parent()->canCreate();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canCreate($member = null) {
- $extended = $this->extendedCan(__FUNCTION__, $member);
- if($extended !== null) {
- return $extended;
- }
- return $this->Parent()->canCreate();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canView($member = null)
+ {
+ $extended = $this->extendedCan(__FUNCTION__, $member);
+ if ($extended !== null) {
+ return $extended;
+ }
+ return $this->Parent()->canView();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canView($member = null) {
- $extended = $this->extendedCan(__FUNCTION__, $member);
- if($extended !== null) {
- return $extended;
- }
- return $this->Parent()->canView();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canEdit($member = null)
+ {
+ $extended = $this->extendedCan(__FUNCTION__, $member);
+ if ($extended !== null) {
+ return $extended;
+ }
+ return $this->Parent()->canEdit();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canEdit($member = null) {
- $extended = $this->extendedCan(__FUNCTION__, $member);
- if($extended !== null) {
- return $extended;
- }
- return $this->Parent()->canEdit();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canDelete($member = null)
+ {
+ $extended = $this->extendedCan(__FUNCTION__, $member);
+ if ($extended !== null) {
+ return $extended;
+ }
+ return $this->Parent()->canDelete();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canDelete($member = null) {
- $extended = $this->extendedCan(__FUNCTION__, $member);
- if($extended !== null) {
- return $extended;
- }
- return $this->Parent()->canDelete();
- }
+ /**
+ * Before we delete this form make sure we delete all the
+ * field values so that we don't leave old data round
+ *
+ * @return void
+ */
+ protected function onBeforeDelete()
+ {
+ if ($this->Values()) {
+ foreach ($this->Values() as $value) {
+ $value->delete();
+ }
+ }
- /**
- * Before we delete this form make sure we delete all the
- * field values so that we don't leave old data round
- *
- * @return void
- */
- protected function onBeforeDelete() {
- if($this->Values()) {
- foreach($this->Values() as $value) {
- $value->delete();
- }
- }
-
- parent::onBeforeDelete();
- }
+ parent::onBeforeDelete();
+ }
}
diff --git a/code/model/submissions/SubmittedFormField.php b/code/model/submissions/SubmittedFormField.php
index 50b1067..c639e55 100755
--- a/code/model/submissions/SubmittedFormField.php
+++ b/code/model/submissions/SubmittedFormField.php
@@ -5,93 +5,101 @@
* @package userforms
*/
-class SubmittedFormField extends DataObject {
+class SubmittedFormField extends DataObject
+{
- private static $db = array(
- "Name" => "Varchar",
- "Value" => "Text",
- "Title" => "Varchar(255)"
- );
+ private static $db = array(
+ "Name" => "Varchar",
+ "Value" => "Text",
+ "Title" => "Varchar(255)"
+ );
- private static $has_one = array(
- "Parent" => "SubmittedForm"
- );
+ private static $has_one = array(
+ "Parent" => "SubmittedForm"
+ );
- private static $summary_fields = array(
- 'Title' => 'Title',
- 'FormattedValue' => 'Value'
- );
+ private static $summary_fields = array(
+ 'Title' => 'Title',
+ 'FormattedValue' => 'Value'
+ );
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canCreate($member = null) {
- return $this->Parent()->canCreate();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canCreate($member = null)
+ {
+ return $this->Parent()->canCreate();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canView($member = null) {
- return $this->Parent()->canView();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canView($member = null)
+ {
+ return $this->Parent()->canView();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canEdit($member = null) {
- return $this->Parent()->canEdit();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canEdit($member = null)
+ {
+ return $this->Parent()->canEdit();
+ }
- /**
- * @param Member
- *
- * @return boolean
- */
- public function canDelete($member = null) {
- return $this->Parent()->canDelete();
- }
+ /**
+ * @param Member
+ *
+ * @return boolean
+ */
+ public function canDelete($member = null)
+ {
+ return $this->Parent()->canDelete();
+ }
- /**
- * Generate a formatted value for the reports and email notifications.
- * Converts new lines (which are stored in the database text field) as
- * so they will output as newlines in the reports
- *
- * @return string
- */
- public function getFormattedValue() {
- return nl2br($this->dbObject('Value')->ATT());
- }
+ /**
+ * Generate a formatted value for the reports and email notifications.
+ * Converts new lines (which are stored in the database text field) as
+ * so they will output as newlines in the reports
+ *
+ * @return string
+ */
+ public function getFormattedValue()
+ {
+ return nl2br($this->dbObject('Value')->ATT());
+ }
- /**
- * Return the value of this submitted form field suitable for inclusion
- * into the CSV
- *
- * @return Text
- */
- public function getExportValue() {
- return $this->Value;
- }
+ /**
+ * Return the value of this submitted form field suitable for inclusion
+ * into the CSV
+ *
+ * @return Text
+ */
+ public function getExportValue()
+ {
+ return $this->Value;
+ }
- /**
- * Find equivalent editable field for this submission.
- *
- * Note the field may have been modified or deleted from the original form
- * so this may not always return the data you expect. If you need to save
- * a particular state of editable form field at time of submission, copy
- * that value to the submission.
- *
- * @return EditableFormField
- */
- public function getEditableField() {
- return $this->Parent()->Parent()->Fields()->filter(array(
- 'Name' => $this->Name
- ))->First();
- }
+ /**
+ * Find equivalent editable field for this submission.
+ *
+ * Note the field may have been modified or deleted from the original form
+ * so this may not always return the data you expect. If you need to save
+ * a particular state of editable form field at time of submission, copy
+ * that value to the submission.
+ *
+ * @return EditableFormField
+ */
+ public function getEditableField()
+ {
+ return $this->Parent()->Parent()->Fields()->filter(array(
+ 'Name' => $this->Name
+ ))->First();
+ }
}
diff --git a/code/modifiers/DisambiguationSegmentFieldModifier.php b/code/modifiers/DisambiguationSegmentFieldModifier.php
index 862f629..2ceb9c5 100644
--- a/code/modifiers/DisambiguationSegmentFieldModifier.php
+++ b/code/modifiers/DisambiguationSegmentFieldModifier.php
@@ -2,53 +2,56 @@
use SilverStripe\Forms\SegmentFieldModifier\AbstractSegmentFieldModifier;
-class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier {
- /**
- * @inheritdoc
- *
- * @param string $value
- *
- * @return string
- */
- public function getPreview($value) {
- if($this->form instanceof Form && $record = $this->form->getRecord()) {
- $parent = $record->Parent();
+class DisambiguationSegmentFieldModifier extends AbstractSegmentFieldModifier
+{
+ /**
+ * @inheritdoc
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function getPreview($value)
+ {
+ if ($this->form instanceof Form && $record = $this->form->getRecord()) {
+ $parent = $record->Parent();
- $try = $value;
+ $try = $value;
- $sibling = EditableformField::get()
- ->filter('ParentID', $parent->ID)
- ->filter('Name', $try)
- ->where('"ID" != ' . $record->ID)
- ->first();
+ $sibling = EditableformField::get()
+ ->filter('ParentID', $parent->ID)
+ ->filter('Name', $try)
+ ->where('"ID" != ' . $record->ID)
+ ->first();
- $counter = 1;
+ $counter = 1;
- while($sibling !== null) {
- $try = $value . '_' . $counter++;
+ while ($sibling !== null) {
+ $try = $value . '_' . $counter++;
- $sibling = EditableformField::get()
- ->filter('ParentID', $parent->ID)
- ->filter('Name', $try)
- ->first();
- }
+ $sibling = EditableformField::get()
+ ->filter('ParentID', $parent->ID)
+ ->filter('Name', $try)
+ ->first();
+ }
- if ($try !== $value) {
- return $try;
- }
- }
+ if ($try !== $value) {
+ return $try;
+ }
+ }
- return $value;
- }
+ return $value;
+ }
- /**
- * @inheritdoc
- *
- * @param string $value
- *
- * @return string
- */
- public function getSuggestion($value) {
- return $this->getPreview($value);
- }
+ /**
+ * @inheritdoc
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function getSuggestion($value)
+ {
+ return $this->getPreview($value);
+ }
}
diff --git a/code/modifiers/UnderscoreSegmentFieldModifier.php b/code/modifiers/UnderscoreSegmentFieldModifier.php
index cbdae2d..e11d466 100644
--- a/code/modifiers/UnderscoreSegmentFieldModifier.php
+++ b/code/modifiers/UnderscoreSegmentFieldModifier.php
@@ -2,26 +2,29 @@
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;
-class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier {
- /**
- * @inheritdoc
- *
- * @param string $value
- *
- * @return string
- */
- public function getPreview($value) {
- return str_replace('-', '_', parent::getPreview($value));
- }
+class UnderscoreSegmentFieldModifier extends SlugSegmentFieldModifier
+{
+ /**
+ * @inheritdoc
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function getPreview($value)
+ {
+ return str_replace('-', '_', parent::getPreview($value));
+ }
- /**
- * @inheritdoc
- *
- * @param string $value
- *
- * @return string
- */
- public function getSuggestion($value) {
- return str_replace('-', '_', parent::getSuggestion($value));
- }
+ /**
+ * @inheritdoc
+ *
+ * @param string $value
+ *
+ * @return string
+ */
+ public function getSuggestion($value)
+ {
+ return str_replace('-', '_', parent::getSuggestion($value));
+ }
}
diff --git a/code/tasks/UserFormsColumnCleanTask.php b/code/tasks/UserFormsColumnCleanTask.php
index b14599d..7002f2a 100644
--- a/code/tasks/UserFormsColumnCleanTask.php
+++ b/code/tasks/UserFormsColumnCleanTask.php
@@ -8,54 +8,54 @@
* @package userforms
*/
-class UserFormsColumnCleanTask extends MigrationTask {
+class UserFormsColumnCleanTask extends MigrationTask
+{
- protected $title = "UserForms EditableFormField Column Clean task";
+ protected $title = "UserForms EditableFormField Column Clean task";
- protected $description = "Removes unused columns from EditableFormField for MySQL databases;";
+ protected $description = "Removes unused columns from EditableFormField for MySQL databases;";
- protected $tables = array('EditableFormField');
+ protected $tables = array('EditableFormField');
- protected $keepColumns = array('ID');
+ protected $keepColumns = array('ID');
- /**
- * Publish the existing forms.
- *
- */
- public function run($request) {
- foreach ($this->tables as $db) {
- $obj = new $db();
- $columns = $obj->database_fields($db);
- $query = "SHOW COLUMNS FROM $db";
- $liveColumns = DB::query($query)->column();
- $backedUp = 0;
- $query = "SHOW TABLES LIKE 'Backup_$db'";
- $tableExists = DB::query($query)->value();
- if ($tableExists != null) {
- echo "Tasks run already on $db exiting";
- return;
- }
- $backedUp = 0;
- foreach ($liveColumns as $index => $column) {
- if ($backedUp == 0) {
- echo "Backing up $db ";
- echo "Creating Backup_$db ";
- // backup table
- $query = "CREATE TABLE Backup_$db LIKE $db";
- DB::query($query);
- echo "Populating Backup_$db ";
- $query = "INSERT Backup_$db SELECT * FROM $db";
- DB::query($query);
- $backedUp = 1;
- }
- if (!isset($columns[$column]) && !in_array($column, $this->keepColumns)) {
- echo "Dropping $column from $db ";
- $query = "ALTER TABLE $db DROP COLUMN $column";
- DB::query($query);
- }
- }
- }
- }
+ /**
+ * Publish the existing forms.
+ *
+ */
+ public function run($request)
+ {
+ foreach ($this->tables as $db) {
+ $obj = new $db();
+ $columns = $obj->database_fields($db);
+ $query = "SHOW COLUMNS FROM $db";
+ $liveColumns = DB::query($query)->column();
+ $backedUp = 0;
+ $query = "SHOW TABLES LIKE 'Backup_$db'";
+ $tableExists = DB::query($query)->value();
+ if ($tableExists != null) {
+ echo "Tasks run already on $db exiting";
+ return;
+ }
+ $backedUp = 0;
+ foreach ($liveColumns as $index => $column) {
+ if ($backedUp == 0) {
+ echo "Backing up $db ";
+ echo "Creating Backup_$db ";
+ // backup table
+ $query = "CREATE TABLE Backup_$db LIKE $db";
+ DB::query($query);
+ echo "Populating Backup_$db ";
+ $query = "INSERT Backup_$db SELECT * FROM $db";
+ DB::query($query);
+ $backedUp = 1;
+ }
+ if (!isset($columns[$column]) && !in_array($column, $this->keepColumns)) {
+ echo "Dropping $column from $db ";
+ $query = "ALTER TABLE $db DROP COLUMN $column";
+ DB::query($query);
+ }
+ }
+ }
+ }
}
-
-
diff --git a/code/tasks/UserFormsUpgradeService.php b/code/tasks/UserFormsUpgradeService.php
index dc17b22..77f20de 100644
--- a/code/tasks/UserFormsUpgradeService.php
+++ b/code/tasks/UserFormsUpgradeService.php
@@ -3,216 +3,225 @@
/**
* Service to support upgrade of userforms module
*/
-class UserFormsUpgradeService {
+class UserFormsUpgradeService
+{
- /**
- * @var bool
- */
- protected $quiet;
+ /**
+ * @var bool
+ */
+ protected $quiet;
- public function run() {
- $this->log("Upgrading formfield rules and custom settings");
+ public function run()
+ {
+ $this->log("Upgrading formfield rules and custom settings");
- // List of rules that have been created in all stages
- $fields = Versioned::get_including_deleted('EditableFormField');
- foreach($fields as $field) {
- $this->upgradeField($field);
- }
- }
+ // List of rules that have been created in all stages
+ $fields = Versioned::get_including_deleted('EditableFormField');
+ foreach ($fields as $field) {
+ $this->upgradeField($field);
+ }
+ }
- /**
- * Migrate a versioned field in all stages
- *
- * @param EditableFormField $field
- */
- protected function upgradeField(EditableFormField $field) {
- $this->log("Upgrading formfield ID = ".$field->ID);
+ /**
+ * Migrate a versioned field in all stages
+ *
+ * @param EditableFormField $field
+ */
+ protected function upgradeField(EditableFormField $field)
+ {
+ $this->log("Upgrading formfield ID = ".$field->ID);
- // Check versions this field exists on
- $filter = sprintf('"EditableFormField"."ID" = \'%d\' AND "Migrated" = 0', $field->ID);
- $stageField = Versioned::get_one_by_stage('EditableFormField', 'Stage', $filter);
- $liveField = Versioned::get_one_by_stage('EditableFormField', 'Live', $filter);
+ // Check versions this field exists on
+ $filter = sprintf('"EditableFormField"."ID" = \'%d\' AND "Migrated" = 0', $field->ID);
+ $stageField = Versioned::get_one_by_stage('EditableFormField', 'Stage', $filter);
+ $liveField = Versioned::get_one_by_stage('EditableFormField', 'Live', $filter);
- if($stageField) {
- $this->upgradeFieldInStage($stageField, 'Stage');
- }
+ if ($stageField) {
+ $this->upgradeFieldInStage($stageField, 'Stage');
+ }
- if($liveField) {
- $this->upgradeFieldInStage($liveField, 'Live');
- }
- }
+ if ($liveField) {
+ $this->upgradeFieldInStage($liveField, 'Live');
+ }
+ }
- /**
- * Migrate a versioned field in a single stage
- *
- * @param EditableFormField $field
- * @param stage $stage
- */
- protected function upgradeFieldInStage(EditableFormField $field, $stage) {
- Versioned::reading_stage($stage);
+ /**
+ * Migrate a versioned field in a single stage
+ *
+ * @param EditableFormField $field
+ * @param stage $stage
+ */
+ protected function upgradeFieldInStage(EditableFormField $field, $stage)
+ {
+ Versioned::reading_stage($stage);
- // Migrate field rules
- $this->migrateRules($field, $stage);
+ // Migrate field rules
+ $this->migrateRules($field, $stage);
- // Migrate custom settings
- $this->migrateCustomSettings($field, $stage);
+ // Migrate custom settings
+ $this->migrateCustomSettings($field, $stage);
- // Flag as migrated
- $field->Migrated = true;
- $field->write();
- }
+ // Flag as migrated
+ $field->Migrated = true;
+ $field->write();
+ }
- /**
- * Migrate custom rules for the given field
- *
- * @param EditableFormField $field
- * @param string $stage
- */
- protected function migrateRules(EditableFormField $field, $stage) {
- $rulesData = $field->CustomRules
- ? unserialize($field->CustomRules)
- : array();
+ /**
+ * Migrate custom rules for the given field
+ *
+ * @param EditableFormField $field
+ * @param string $stage
+ */
+ protected function migrateRules(EditableFormField $field, $stage)
+ {
+ $rulesData = $field->CustomRules
+ ? unserialize($field->CustomRules)
+ : array();
- // Skip blank rules or fields with custom rules already
- if(empty($rulesData) || $field->DisplayRules()->count()) {
- return;
- }
+ // Skip blank rules or fields with custom rules already
+ if (empty($rulesData) || $field->DisplayRules()->count()) {
+ return;
+ }
- // Check value of this condition
- foreach($rulesData as $ruleDataItem) {
- if(empty($ruleDataItem['ConditionOption']) || empty($ruleDataItem['Display'])) {
- continue;
- }
+ // Check value of this condition
+ foreach ($rulesData as $ruleDataItem) {
+ if (empty($ruleDataItem['ConditionOption']) || empty($ruleDataItem['Display'])) {
+ continue;
+ }
- // Get data for this rule
- $conditionOption = $ruleDataItem['ConditionOption'];
- $display = $ruleDataItem['Display'];
- $conditionFieldName = empty($ruleDataItem['ConditionField']) ? null : $ruleDataItem['ConditionField'];
- $value = isset($ruleDataItem['Value'])
- ? $ruleDataItem['Value']
- : null;
+ // Get data for this rule
+ $conditionOption = $ruleDataItem['ConditionOption'];
+ $display = $ruleDataItem['Display'];
+ $conditionFieldName = empty($ruleDataItem['ConditionField']) ? null : $ruleDataItem['ConditionField'];
+ $value = isset($ruleDataItem['Value'])
+ ? $ruleDataItem['Value']
+ : null;
- // Create rule
- $rule = $this->findOrCreateRule($field, $stage, $conditionOption, $display, $conditionFieldName, $value);
- $this->log("Upgrading rule ID = " . $rule->ID);
- }
- }
+ // Create rule
+ $rule = $this->findOrCreateRule($field, $stage, $conditionOption, $display, $conditionFieldName, $value);
+ $this->log("Upgrading rule ID = " . $rule->ID);
+ }
+ }
- /**
- * Migrate custom settings for the given field
- *
- * @param EditableFormField $field
- * @param string $stage
- */
- protected function migrateCustomSettings(EditableFormField $field, $stage) {
- // Custom settings include:
- // - ExtraClass
- // - RightTitle
- // - ShowOnLoad (show or '' are treated as true)
- //
- // - CheckedDefault (new field on EditableCheckbox - should be read from old "default" value)
- // - Default (EditableCheckbox)
- // - DefaultToToday (EditableDateField)
- // - Folder (EditableFileField)
- // - Level (EditableFormHeading)
- // - HideFromReports (EditableFormHeading / EditableLiteralField)
- // - Content (EditableLiteralField)
- // - GroupID (EditableMemberListField)
- // - MinValue (EditableNumericField)
- // - MaxValue (EditableNumericField)
- // - MinLength (EditableTextField)
- // - MaxLength (EditableTextField)
- // - Rows (EditableTextField)
+ /**
+ * Migrate custom settings for the given field
+ *
+ * @param EditableFormField $field
+ * @param string $stage
+ */
+ protected function migrateCustomSettings(EditableFormField $field, $stage)
+ {
+ // Custom settings include:
+ // - ExtraClass
+ // - RightTitle
+ // - ShowOnLoad (show or '' are treated as true)
+ //
+ // - CheckedDefault (new field on EditableCheckbox - should be read from old "default" value)
+ // - Default (EditableCheckbox)
+ // - DefaultToToday (EditableDateField)
+ // - Folder (EditableFileField)
+ // - Level (EditableFormHeading)
+ // - HideFromReports (EditableFormHeading / EditableLiteralField)
+ // - Content (EditableLiteralField)
+ // - GroupID (EditableMemberListField)
+ // - MinValue (EditableNumericField)
+ // - MaxValue (EditableNumericField)
+ // - MinLength (EditableTextField)
+ // - MaxLength (EditableTextField)
+ // - Rows (EditableTextField)
- $customSettings = $field->CustomSettings
- ? unserialize($field->CustomSettings)
- : array();
+ $customSettings = $field->CustomSettings
+ ? unserialize($field->CustomSettings)
+ : array();
- // Skip blank rules or fields with custom rules already
- if(empty($customSettings)) {
- return;
- }
+ // Skip blank rules or fields with custom rules already
+ if (empty($customSettings)) {
+ return;
+ }
- $field->migrateSettings($customSettings);
- $field->write();
- }
+ $field->migrateSettings($customSettings);
+ $field->write();
+ }
- /**
- * Create or find an existing field with the matched specification
- *
- * @param EditableFormField $field
- * @param string $stage
- * @param string $conditionOption
- * @param string $display
- * @param string $conditionFieldName
- * @param string $value
- * @return EditableCustomRule
- */
- protected function findOrCreateRule(EditableFormField $field, $stage, $conditionOption, $display, $conditionFieldName, $value) {
- // Get id of field
- $conditionField = $conditionFieldName
- ? EditableFormField::get()->filter('Name', $conditionFieldName)->first()
- : null;
+ /**
+ * Create or find an existing field with the matched specification
+ *
+ * @param EditableFormField $field
+ * @param string $stage
+ * @param string $conditionOption
+ * @param string $display
+ * @param string $conditionFieldName
+ * @param string $value
+ * @return EditableCustomRule
+ */
+ protected function findOrCreateRule(EditableFormField $field, $stage, $conditionOption, $display, $conditionFieldName, $value)
+ {
+ // Get id of field
+ $conditionField = $conditionFieldName
+ ? EditableFormField::get()->filter('Name', $conditionFieldName)->first()
+ : null;
- // If live, search stage record for matching one
- if($stage === 'Live') {
- $list = Versioned::get_by_stage('EditableCustomRule', 'Stage')
- ->filter(array(
- 'ParentID' => $field->ID,
- 'ConditionFieldID' => $conditionField ? $conditionField->ID : 0,
- 'Display' => $display,
- 'ConditionOption' => $conditionOption
- ));
- if($value) {
- $list = $list->filter('FieldValue', $value);
- } else {
- $list = $list->where('"FieldValue" IS NULL OR "FieldValue" = \'\'');
- }
- $rule = $list->first();
- if($rule) {
- $rule->write();
- $rule->publish("Stage", "Live");
- return $rule;
- }
- }
+ // If live, search stage record for matching one
+ if ($stage === 'Live') {
+ $list = Versioned::get_by_stage('EditableCustomRule', 'Stage')
+ ->filter(array(
+ 'ParentID' => $field->ID,
+ 'ConditionFieldID' => $conditionField ? $conditionField->ID : 0,
+ 'Display' => $display,
+ 'ConditionOption' => $conditionOption
+ ));
+ if ($value) {
+ $list = $list->filter('FieldValue', $value);
+ } else {
+ $list = $list->where('"FieldValue" IS NULL OR "FieldValue" = \'\'');
+ }
+ $rule = $list->first();
+ if ($rule) {
+ $rule->write();
+ $rule->publish("Stage", "Live");
+ return $rule;
+ }
+ }
- // If none found, or in stage, create new record
- $rule = new EditableCustomRule();
- $rule->ParentID = $field->ID;
- $rule->ConditionFieldID = $conditionField ? $conditionField->ID : 0;
- $rule->Display = $display;
- $rule->ConditionOption = $conditionOption;
- $rule->FieldValue = $value;
- $rule->write();
- return $rule;
- }
+ // If none found, or in stage, create new record
+ $rule = new EditableCustomRule();
+ $rule->ParentID = $field->ID;
+ $rule->ConditionFieldID = $conditionField ? $conditionField->ID : 0;
+ $rule->Display = $display;
+ $rule->ConditionOption = $conditionOption;
+ $rule->FieldValue = $value;
+ $rule->write();
+ return $rule;
+ }
- public function log($message) {
- if($this->getQuiet()) {
- return;
- }
- if(Director::is_cli()) {
- echo "{$message}\n";
- } else {
- echo "{$message} ";
- }
- }
+ public function log($message)
+ {
+ if ($this->getQuiet()) {
+ return;
+ }
+ if (Director::is_cli()) {
+ echo "{$message}\n";
+ } else {
+ echo "{$message} ";
+ }
+ }
- /**
- * Set if this service should be quiet
- *
- * @param bool $quiet
- * @return $ths
- */
- public function setQuiet($quiet) {
- $this->quiet = $quiet;
- return $this;
- }
-
- public function getQuiet() {
- return $this->quiet;
- }
+ /**
+ * Set if this service should be quiet
+ *
+ * @param bool $quiet
+ * @return $ths
+ */
+ public function setQuiet($quiet)
+ {
+ $this->quiet = $quiet;
+ return $this;
+ }
+ public function getQuiet()
+ {
+ return $this->quiet;
+ }
}
diff --git a/code/tasks/UserFormsUpgradeTask.php b/code/tasks/UserFormsUpgradeTask.php
index 86f6d62..9a05be7 100644
--- a/code/tasks/UserFormsUpgradeTask.php
+++ b/code/tasks/UserFormsUpgradeTask.php
@@ -5,17 +5,19 @@
*
* @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) {
- $service = Injector::inst()->create('UserFormsUpgradeService');
- $service->log("Upgrading userforms module");
- $service->setQuiet(false)
- ->run();
- $service->log("Done");
- }
+ public function run($request)
+ {
+ $service = Injector::inst()->create('UserFormsUpgradeService');
+ $service->log("Upgrading userforms module");
+ $service->setQuiet(false)
+ ->run();
+ $service->log("Done");
+ }
}
diff --git a/code/tasks/UserFormsVersionedTask.php b/code/tasks/UserFormsVersionedTask.php
index 201d3d9..45335b1 100644
--- a/code/tasks/UserFormsVersionedTask.php
+++ b/code/tasks/UserFormsVersionedTask.php
@@ -10,30 +10,29 @@
* @package userforms
*/
-class UserFormsVersionedTask extends MigrationTask {
+class UserFormsVersionedTask extends MigrationTask
+{
- protected $title = "UserForms Versioned Initial Migration";
+ protected $title = "UserForms Versioned Initial Migration";
- protected $description = "Publishes the existing forms";
+ protected $description = "Publishes the existing forms";
- /**
- * Publish the existing forms.
- *
- */
- public function run($request) {
- $forms = Versioned::get_by_stage('UserDefinedForm', 'Live');
+ /**
+ * Publish the existing forms.
+ *
+ */
+ public function run($request)
+ {
+ $forms = Versioned::get_by_stage('UserDefinedForm', 'Live');
- if($forms) {
- foreach($forms as $form) {
- echo "Publishing $form->Title ";
- $form->doPublish();
- }
- echo "Complete";
- }
- else {
- echo "No Forms Found";
- }
- }
+ if ($forms) {
+ foreach ($forms as $form) {
+ echo "Publishing $form->Title ";
+ $form->doPublish();
+ }
+ echo "Complete";
+ } else {
+ echo "No Forms Found";
+ }
+ }
}
-
-
diff --git a/tests/EditableFormFieldTest.php b/tests/EditableFormFieldTest.php
index 95998cb..79981fe 100644
--- a/tests/EditableFormFieldTest.php
+++ b/tests/EditableFormFieldTest.php
@@ -4,167 +4,178 @@
* @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() {
- $text = $this->objFromFixture('EditableTextField', 'basic-text');
+ public function testFormFieldPermissions()
+ {
+ $text = $this->objFromFixture('EditableTextField', 'basic-text');
- $this->logInWithPermission('ADMIN');
- $this->assertTrue($text->canCreate());
- $this->assertTrue($text->canView());
- $this->assertTrue($text->canEdit());
- $this->assertTrue($text->canDelete());
+ $this->logInWithPermission('ADMIN');
+ $this->assertTrue($text->canCreate());
+ $this->assertTrue($text->canView());
+ $this->assertTrue($text->canEdit());
+ $this->assertTrue($text->canDelete());
- $text->setReadonly(true);
- $this->assertTrue($text->canView());
- $this->assertFalse($text->canEdit());
- $this->assertFalse($text->canDelete());
+ $text->setReadonly(true);
+ $this->assertTrue($text->canView());
+ $this->assertFalse($text->canEdit());
+ $this->assertFalse($text->canDelete());
- $text->setReadonly(false);
- $this->assertTrue($text->canView());
- $this->assertTrue($text->canEdit());
- $this->assertTrue($text->canDelete());
+ $text->setReadonly(false);
+ $this->assertTrue($text->canView());
+ $this->assertTrue($text->canEdit());
+ $this->assertTrue($text->canDelete());
- $member = Member::currentUser();
- $member->logout();
+ $member = Member::currentUser();
+ $member->logout();
- $this->logInWithPermission('SITETREE_VIEW_ALL');
- $this->assertFalse($text->canCreate());
+ $this->logInWithPermission('SITETREE_VIEW_ALL');
+ $this->assertFalse($text->canCreate());
- $text->setReadonly(false);
- $this->assertTrue($text->canView());
- $this->assertFalse($text->canEdit());
- $this->assertFalse($text->canDelete());
+ $text->setReadonly(false);
+ $this->assertTrue($text->canView());
+ $this->assertFalse($text->canEdit());
+ $this->assertFalse($text->canDelete());
- $text->setReadonly(true);
- $this->assertTrue($text->canView());
- $this->assertFalse($text->canEdit());
- $this->assertFalse($text->canDelete());
- }
+ $text->setReadonly(true);
+ $this->assertTrue($text->canView());
+ $this->assertFalse($text->canEdit());
+ $this->assertFalse($text->canDelete());
+ }
- function testCustomRules() {
- $this->logInWithPermission('ADMIN');
- $form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
+ public function testCustomRules()
+ {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
- $checkbox = $form->Fields()->find('ClassName', 'EditableCheckbox');
- $field = $form->Fields()->find('ClassName', 'EditableTextField');
+ $checkbox = $form->Fields()->find('ClassName', 'EditableCheckbox');
+ $field = $form->Fields()->find('ClassName', 'EditableTextField');
- $rules = $checkbox->DisplayRules();
+ $rules = $checkbox->DisplayRules();
- // form has 2 fields - a checkbox and a text field
- // it has 1 rule - when ticked the checkbox hides the text field
- $this->assertEquals(1, $rules->Count());
- $this->assertEquals($rules, $checkbox->EffectiveDisplayRules());
+ // form has 2 fields - a checkbox and a text field
+ // it has 1 rule - when ticked the checkbox hides the text field
+ $this->assertEquals(1, $rules->Count());
+ $this->assertEquals($rules, $checkbox->EffectiveDisplayRules());
- $checkboxRule = $rules->First();
- $checkboxRule->ConditionFieldID = $field->ID;
+ $checkboxRule = $rules->First();
+ $checkboxRule->ConditionFieldID = $field->ID;
- $this->assertEquals($checkboxRule->Display, 'Hide');
- $this->assertEquals($checkboxRule->ConditionOption, 'HasValue');
- $this->assertEquals($checkboxRule->FieldValue, '6');
+ $this->assertEquals($checkboxRule->Display, 'Hide');
+ $this->assertEquals($checkboxRule->ConditionOption, 'HasValue');
+ $this->assertEquals($checkboxRule->FieldValue, '6');
- // If field is required then all custom rules are disabled
- $checkbox->Required = true;
- $this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count());
- }
+ // If field is required then all custom rules are disabled
+ $checkbox->Required = true;
+ $this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count());
+ }
/**
* @covers EditableOption::getValue
*/
- public function testEditableOptionEmptyValue() {
- $option = $this->objFromFixture('EditableOption', 'option-1');
- $option->Value = '';
+ public function testEditableOptionEmptyValue()
+ {
+ $option = $this->objFromFixture('EditableOption', 'option-1');
+ $option->Value = '';
// Disallow empty values
EditableOption::set_allow_empty_values(false);
- $this->assertEquals($option->Title, $option->Value);
+ $this->assertEquals($option->Title, $option->Value);
- $option->Value = 'test';
- $this->assertEquals('test', $option->Value);
+ $option->Value = 'test';
+ $this->assertEquals('test', $option->Value);
// Allow empty values
EditableOption::set_allow_empty_values(true);
- $option->Value = '';
- $this->assertEquals('', $option->Value);
+ $option->Value = '';
+ $this->assertEquals('', $option->Value);
}
- function testEditableDropdownField() {
- $dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
+ public function testEditableDropdownField()
+ {
+ $dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
- $field = $dropdown->getFormField();
+ $field = $dropdown->getFormField();
- $this->assertThat($field, $this->isInstanceOf('DropdownField'));
- $values = $field->getSource();
+ $this->assertThat($field, $this->isInstanceOf('DropdownField'));
+ $values = $field->getSource();
- $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() {
- $radio = $this->objFromFixture('EditableRadioField', 'radio-field');
+ public function testEditableRadioField()
+ {
+ $radio = $this->objFromFixture('EditableRadioField', 'radio-field');
- $field = $radio->getFormField();
+ $field = $radio->getFormField();
- $this->assertThat($field, $this->isInstanceOf('OptionsetField'));
- $values = $field->getSource();
+ $this->assertThat($field, $this->isInstanceOf('OptionsetField'));
+ $values = $field->getSource();
- $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() {
- $dropdown = $this->objFromFixture('EditableDropdown','basic-dropdown');
+ public function testMultipleOptionDuplication()
+ {
+ $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) {
- $orginal = $dropdown->Options()->find('Title', $option->Title);
+ foreach ($clone->Options() as $option) {
+ $orginal = $dropdown->Options()->find('Title', $option->Title);
- $this->assertEquals($orginal->Sort, $option->Sort);
- }
- }
+ $this->assertEquals($orginal->Sort, $option->Sort);
+ }
+ }
- public function testFileField() {
- $fileField = $this->objFromFixture('EditableFileField', 'file-field');
- $formField = $fileField->getFormField();
+ public function testFileField()
+ {
+ $fileField = $this->objFromFixture('EditableFileField', 'file-field');
+ $formField = $fileField->getFormField();
- $this->assertContains('jpg', $formField->getValidator()->getAllowedExtensions());
- $this->assertNotContains('notallowedextension', $formField->getValidator()->getAllowedExtensions());
- }
+ $this->assertContains('jpg', $formField->getValidator()->getAllowedExtensions());
+ $this->assertNotContains('notallowedextension', $formField->getValidator()->getAllowedExtensions());
+ }
- public function testFileFieldAllowedExtensionsBlacklist() {
- Config::inst()->update('EditableFileField', 'allowed_extensions_blacklist', array('jpg'));
- $fileField = $this->objFromFixture('EditableFileField', 'file-field');
- $formField = $fileField->getFormField();
+ public function testFileFieldAllowedExtensionsBlacklist()
+ {
+ Config::inst()->update('EditableFileField', 'allowed_extensions_blacklist', array('jpg'));
+ $fileField = $this->objFromFixture('EditableFileField', 'file-field');
+ $formField = $fileField->getFormField();
- $this->assertNotContains('jpg', $formField->getValidator()->getAllowedExtensions());
- }
+ $this->assertNotContains('jpg', $formField->getValidator()->getAllowedExtensions());
+ }
- /**
- * Verify that unique names are automatically generated for each formfield
- */
- public function testUniqueName() {
- $textfield1 = new EditableTextField();
- $this->assertEmpty($textfield1->Name);
+ /**
+ * Verify that unique names are automatically generated for each formfield
+ */
+ public function testUniqueName()
+ {
+ $textfield1 = new EditableTextField();
+ $this->assertEmpty($textfield1->Name);
- // Write values
- $textfield1->write();
- $textfield2 = new EditableTextField();
- $textfield2->write();
- $checkboxField = new EditableCheckbox();
- $checkboxField->write();
+ // Write values
+ $textfield1->write();
+ $textfield2 = new EditableTextField();
+ $textfield2->write();
+ $checkboxField = new EditableCheckbox();
+ $checkboxField->write();
- // Test values are in the expected format
- $this->assertRegExp('/^EditableTextField_.+/', $textfield1->Name);
- $this->assertRegExp('/^EditableTextField_.+/', $textfield2->Name);
- $this->assertRegExp('/^EditableCheckbox_.+/', $checkboxField->Name);
- $this->assertNotEquals($textfield1->Name, $textfield2->Name);
- }
+ // Test values are in the expected format
+ $this->assertRegExp('/^EditableTextField_.+/', $textfield1->Name);
+ $this->assertRegExp('/^EditableTextField_.+/', $textfield2->Name);
+ $this->assertRegExp('/^EditableCheckbox_.+/', $checkboxField->Name);
+ $this->assertNotEquals($textfield1->Name, $textfield2->Name);
+ }
- public function testLengthRange() {
+ public function testLengthRange()
+ {
/** @var EditableTextField $textField */
$textField = $this->objFromFixture('EditableTextField', 'basic-text');
@@ -193,6 +204,4 @@ class EditableFormFieldTest extends FunctionalTest {
$this->assertEquals(10, $attributes['data-rule-minlength']);
$this->assertEquals(20, $attributes['data-rule-maxlength']);
}
-
-
}
diff --git a/tests/EditableLiteralFieldTest.php b/tests/EditableLiteralFieldTest.php
index b4cfa4b..9dd31ae 100644
--- a/tests/EditableLiteralFieldTest.php
+++ b/tests/EditableLiteralFieldTest.php
@@ -3,40 +3,44 @@
/**
* Tests the {@see EditableLiteralField} class
*/
-class EditableLiteralFieldTest extends SapphireTest {
+class EditableLiteralFieldTest extends SapphireTest
+{
- public function setUp() {
- parent::setUp();
- HtmlEditorConfig::set_active('cms');
- }
+ public function setUp()
+ {
+ parent::setUp();
+ HtmlEditorConfig::set_active('cms');
+ }
- /**
- * Tests the sanitisation of HTML content
- */
- public function testSanitisation() {
- $rawContent = '
Welcome
Giant Robots!
';
- $safeContent = '
Welcome
Giant Robots!
';
- $field = new EditableLiteralField();
+ /**
+ * Tests the sanitisation of HTML content
+ */
+ public function testSanitisation()
+ {
+ $rawContent = '
Welcome
Giant Robots!
';
+ $safeContent = '
Welcome
Giant Robots!
';
+ $field = new EditableLiteralField();
- // Test with sanitisation enabled
- Config::inst()->update('HtmlEditorField', 'sanitise_server_side', true);
- $field->setContent($rawContent);
- $this->assertEquals($safeContent, $field->getContent());
+ // Test with sanitisation enabled
+ Config::inst()->update('HtmlEditorField', 'sanitise_server_side', true);
+ $field->setContent($rawContent);
+ $this->assertEquals($safeContent, $field->getContent());
- // Test with sanitisation disabled
- Config::inst()->remove('HtmlEditorField', 'sanitise_server_side');
- $field->setContent($rawContent);
- $this->assertEquals($rawContent, $field->getContent());
- }
+ // Test with sanitisation disabled
+ Config::inst()->remove('HtmlEditorField', 'sanitise_server_side');
+ $field->setContent($rawContent);
+ $this->assertEquals($rawContent, $field->getContent());
+ }
- public function testHideLabel() {
- $field = new EditableLiteralField(array(
- 'Title' => 'Test label'
- ));
+ public function testHideLabel()
+ {
+ $field = new EditableLiteralField(array(
+ 'Title' => 'Test label'
+ ));
- $this->assertContains('Test label', $field->getFormField()->Field());
+ $this->assertContains('Test label', $field->getFormField()->Field());
- $field->HideLabel = true;
- $this->assertNotContains('Test label', $field->getFormField()->Field());
- }
+ $field->HideLabel = true;
+ $this->assertNotContains('Test label', $field->getFormField()->Field());
+ }
}
diff --git a/tests/SecureEditableFileFieldTest.php b/tests/SecureEditableFileFieldTest.php
index c6d56fe..4bc8194 100644
--- a/tests/SecureEditableFileFieldTest.php
+++ b/tests/SecureEditableFileFieldTest.php
@@ -5,79 +5,85 @@
*
* @author dmooyman
*/
-class SecureEditableFileFieldTest extends SapphireTest {
+class SecureEditableFileFieldTest extends SapphireTest
+{
- protected $usesDatabase = true;
+ protected $usesDatabase = true;
- public function setUp() {
- parent::setUp();
+ public function setUp()
+ {
+ parent::setUp();
- if(!class_exists('SecureFileExtension')) {
- $this->skipTest = true;
- $this->markTestSkipped(get_class() . ' skipped unless running with securefiles');
- }
- Config::inst()->update('EditableFileField', 'secure_folder_name', 'SecureEditableFileFieldTest/SecureUploads');
- $this->clearPath();
- }
+ if (!class_exists('SecureFileExtension')) {
+ $this->skipTest = true;
+ $this->markTestSkipped(get_class() . ' skipped unless running with securefiles');
+ }
+ Config::inst()->update('EditableFileField', 'secure_folder_name', 'SecureEditableFileFieldTest/SecureUploads');
+ $this->clearPath();
+ }
- public function tearDown() {
- $this->clearPath();
- parent::tearDown();
- }
+ public function tearDown()
+ {
+ $this->clearPath();
+ parent::tearDown();
+ }
- protected function clearPath() {
- if(file_exists(ASSETS_PATH . '/SecureEditableFileFieldTest')) {
- Filesystem::removeFolder(ASSETS_PATH . '/SecureEditableFileFieldTest');
- }
- }
+ protected function clearPath()
+ {
+ if (file_exists(ASSETS_PATH . '/SecureEditableFileFieldTest')) {
+ Filesystem::removeFolder(ASSETS_PATH . '/SecureEditableFileFieldTest');
+ }
+ }
- /**
- * Test that newly created folders are secure
- */
- public function testCreateFolder() {
- $field = new EditableFileField();
- $field->write();
- $this->assertTrue($field->getIsSecure());
- $this->assertTrue($field->Folder()->exists());
- $this->assertEquals('assets/SecureEditableFileFieldTest/SecureUploads/', $field->Folder()->Filename);
- $this->assertEquals('OnlyTheseUsers', $field->Folder()->CanViewType);
- $this->assertEquals(1, $field->Folder()->ViewerGroups()->first()->Permissions()->filter('code', 'ADMIN')->count());
- }
+ /**
+ * Test that newly created folders are secure
+ */
+ public function testCreateFolder()
+ {
+ $field = new EditableFileField();
+ $field->write();
+ $this->assertTrue($field->getIsSecure());
+ $this->assertTrue($field->Folder()->exists());
+ $this->assertEquals('assets/SecureEditableFileFieldTest/SecureUploads/', $field->Folder()->Filename);
+ $this->assertEquals('OnlyTheseUsers', $field->Folder()->CanViewType);
+ $this->assertEquals(1, $field->Folder()->ViewerGroups()->first()->Permissions()->filter('code', 'ADMIN')->count());
+ }
- /**
- * Test new folders that are created without security enabled
- */
- public function testCreateInsecure() {
- Config::inst()->update('EditableFileField', 'disable_security', true);
+ /**
+ * Test new folders that are created without security enabled
+ */
+ public function testCreateInsecure()
+ {
+ Config::inst()->update('EditableFileField', 'disable_security', true);
- // Esure folder is created without a folder
- $field = new EditableFileField();
- $field->write();
- $this->assertFalse($field->getIsSecure());
- $this->assertFalse($field->Folder()->exists());
+ // Esure folder is created without a folder
+ $field = new EditableFileField();
+ $field->write();
+ $this->assertFalse($field->getIsSecure());
+ $this->assertFalse($field->Folder()->exists());
- // Assigning a non-secure folder doesn't secure this
- $folder = Folder::find_or_make('SecureEditableFileFieldTest/PublicFolder');
- $field->FolderID = $folder->ID;
- $field->write();
+ // Assigning a non-secure folder doesn't secure this
+ $folder = Folder::find_or_make('SecureEditableFileFieldTest/PublicFolder');
+ $field->FolderID = $folder->ID;
+ $field->write();
- $this->assertFalse($field->getIsSecure());
- $this->assertTrue($field->Folder()->exists());
- $this->assertEquals('assets/SecureEditableFileFieldTest/PublicFolder/', $field->Folder()->Filename);
- $this->assertEquals('Inherit', $field->Folder()->CanViewType);
+ $this->assertFalse($field->getIsSecure());
+ $this->assertTrue($field->Folder()->exists());
+ $this->assertEquals('assets/SecureEditableFileFieldTest/PublicFolder/', $field->Folder()->Filename);
+ $this->assertEquals('Inherit', $field->Folder()->CanViewType);
- // Enabling security and re-saving will force this field to be made secure (but not changed)
- Config::inst()->update('EditableFileField', 'disable_security', false);
- singleton('EditableFileField')->requireDefaultRecords();
+ // Enabling security and re-saving will force this field to be made secure (but not changed)
+ Config::inst()->update('EditableFileField', 'disable_security', false);
+ singleton('EditableFileField')->requireDefaultRecords();
- // Reload record from DB
- $field = EditableFileField::get()->byID($field->ID);
+ // Reload record from DB
+ $field = EditableFileField::get()->byID($field->ID);
- // Existing folder is now secured (retro-actively secures any old uploads)
- $this->assertTrue($field->getIsSecure());
- $this->assertTrue($field->Folder()->exists());
- $this->assertEquals('assets/SecureEditableFileFieldTest/PublicFolder/', $field->Folder()->Filename);
- $this->assertEquals('OnlyTheseUsers', $field->Folder()->CanViewType);
- $this->assertEquals(1, $field->Folder()->ViewerGroups()->first()->Permissions()->filter('code', 'ADMIN')->count());
- }
-}
\ No newline at end of file
+ // Existing folder is now secured (retro-actively secures any old uploads)
+ $this->assertTrue($field->getIsSecure());
+ $this->assertTrue($field->Folder()->exists());
+ $this->assertEquals('assets/SecureEditableFileFieldTest/PublicFolder/', $field->Folder()->Filename);
+ $this->assertEquals('OnlyTheseUsers', $field->Folder()->CanViewType);
+ $this->assertEquals(1, $field->Folder()->ViewerGroups()->first()->Permissions()->filter('code', 'ADMIN')->count());
+ }
+}
diff --git a/tests/UserDefinedFormControllerTest.php b/tests/UserDefinedFormControllerTest.php
index a43cd64..75e4c27 100644
--- a/tests/UserDefinedFormControllerTest.php
+++ b/tests/UserDefinedFormControllerTest.php
@@ -4,282 +4,296 @@
* @package userforms
*/
-class UserDefinedFormControllerTest extends FunctionalTest {
+class UserDefinedFormControllerTest extends FunctionalTest
+{
- static $fixture_file = 'UserDefinedFormTest.yml';
+ public static $fixture_file = 'UserDefinedFormTest.yml';
- public function testProcess() {
- $form = $this->setupFormFrontend();
+ public function testProcess()
+ {
+ $form = $this->setupFormFrontend();
- $controller = new UserDefinedFormControllerTest_Controller($form);
+ $controller = new UserDefinedFormControllerTest_Controller($form);
- $this->autoFollowRedirection = false;
- $this->clearEmails();
+ $this->autoFollowRedirection = false;
+ $this->clearEmails();
- // load the form
- $this->get($form->URLSegment);
+ // load the form
+ $this->get($form->URLSegment);
- $field = $this->objFromFixture('EditableTextField', 'basic-text');
+ $field = $this->objFromFixture('EditableTextField', 'basic-text');
- $response = $this->submitForm('UserForm_Form', null, array($field->Name => 'Basic Value'));
+ $response = $this->submitForm('UserForm_Form', null, array($field->Name => 'Basic Value'));
- // should have a submitted form field now
- $submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
- $this->assertDOSAllMatch(array('Name' => 'basic-text-name', 'Value' => 'Basic Value', 'Title' => 'Basic Text Field'), $submitted);
+ // should have a submitted form field now
+ $submitted = DataObject::get('SubmittedFormField', "\"Name\" = 'basic-text-name'");
+ $this->assertDOSAllMatch(array('Name' => 'basic-text-name', 'Value' => 'Basic Value', 'Title' => 'Basic Text Field'), $submitted);
- // check emails
- $this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject');
- $email = $this->findEmail('test@example.com', 'no-reply@example.com', 'Email Subject');
+ // check emails
+ $this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject');
+ $email = $this->findEmail('test@example.com', 'no-reply@example.com', 'Email Subject');
- // assert that the email has the field title and the value html email
- $parser = new CSSContentParser($email['content']);
- $title = $parser->getBySelector('strong');
+ // assert that the email has the field title and the value html email
+ $parser = new CSSContentParser($email['content']);
+ $title = $parser->getBySelector('strong');
- $this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
+ $this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
- $value = $parser->getBySelector('dd');
- $this->assertEquals('Basic Value', (string) $value[0], 'Email contains the value');
+ $value = $parser->getBySelector('dd');
+ $this->assertEquals('Basic Value', (string) $value[0], 'Email contains the value');
- // no html
- $this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
- $nohtml = $this->findEmail('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
+ // no html
+ $this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
+ $nohtml = $this->findEmail('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
- $this->assertContains('Basic Text Field: Basic Value', $nohtml['content'], 'Email contains no html');
+ $this->assertContains('Basic Text Field: Basic Value', $nohtml['content'], 'Email contains no html');
- // no data
- $this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
- $nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
+ // no data
+ $this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
+ $nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
- $parser = new CSSContentParser($nodata['content']);
- $list = $parser->getBySelector('dl');
+ $parser = new CSSContentParser($nodata['content']);
+ $list = $parser->getBySelector('dl');
- $this->assertFalse(isset($list[0]), 'Email contains no fields');
+ $this->assertFalse(isset($list[0]), 'Email contains no fields');
- // check to see if the user was redirected (301)
- $this->assertEquals($response->getStatusCode(), 302);
- $this->assertStringEndsWith('finished#uff', $response->getHeader('Location'));
- }
+ // check to see if the user was redirected (301)
+ $this->assertEquals($response->getStatusCode(), 302);
+ $this->assertStringEndsWith('finished#uff', $response->getHeader('Location'));
+ }
- public function testValidation() {
- $form = $this->setupFormFrontend('email-form');
+ public function testValidation()
+ {
+ $form = $this->setupFormFrontend('email-form');
- // Post with no fields
- $this->get($form->URLSegment);
- $response = $this->submitForm('UserForm_Form', null, array());
- $this->assertPartialMatchBySelector(
- '.field .message',
- array('This field is required')
- );
+ // Post with no fields
+ $this->get($form->URLSegment);
+ $response = $this->submitForm('UserForm_Form', null, array());
+ $this->assertPartialMatchBySelector(
+ '.field .message',
+ array('This field is required')
+ );
- // Post with all fields, but invalid email
- $this->get($form->URLSegment);
- $this->submitForm('UserForm_Form', null, array(
- 'required-email' => 'invalid',
- 'required-text' => 'bob'
- ));
- $this->assertPartialMatchBySelector(
- '.field .message',
- array('Please enter an email address')
- );
+ // Post with all fields, but invalid email
+ $this->get($form->URLSegment);
+ $this->submitForm('UserForm_Form', null, array(
+ 'required-email' => 'invalid',
+ 'required-text' => 'bob'
+ ));
+ $this->assertPartialMatchBySelector(
+ '.field .message',
+ array('Please enter an email address')
+ );
- // Post with only required
- $this->get($form->URLSegment);
- $this->submitForm('UserForm_Form', null, array(
- 'required-text' => 'bob'
- ));
- $this->assertPartialMatchBySelector(
- 'p',
- array("Thanks, we've received your submission.")
- );
- }
+ // Post with only required
+ $this->get($form->URLSegment);
+ $this->submitForm('UserForm_Form', null, array(
+ 'required-text' => 'bob'
+ ));
+ $this->assertPartialMatchBySelector(
+ 'p',
+ array("Thanks, we've received your submission.")
+ );
+ }
- public function testFinished() {
- $form = $this->setupFormFrontend();
+ public function testFinished()
+ {
+ $form = $this->setupFormFrontend();
- // set formProcessed and SecurityID to replicate the form being filled out
- $this->session()->inst_set('SecurityID', 1);
- $this->session()->inst_set('FormProcessed', 1);
+ // set formProcessed and SecurityID to replicate the form being filled out
+ $this->session()->inst_set('SecurityID', 1);
+ $this->session()->inst_set('FormProcessed', 1);
- $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() {
- $form = $this->setupFormFrontend();
+ public function testAppendingFinished()
+ {
+ $form = $this->setupFormFrontend();
- // replicate finished being added to the end of the form URL without the form being filled out
- $this->session()->inst_set('SecurityID', 1);
- $this->session()->inst_set('FormProcessed', null);
+ // replicate finished being added to the end of the form URL without the form being filled out
+ $this->session()->inst_set('SecurityID', 1);
+ $this->session()->inst_set('FormProcessed', null);
- $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() {
- $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ public function testForm()
+ {
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
- $controller = new UserDefinedFormControllerTest_Controller($form);
+ $controller = new UserDefinedFormControllerTest_Controller($form);
- // test form
- $this->assertEquals($controller->Form()->getName(), 'Form', 'The form is referenced as Form');
- $this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
- $this->assertEquals($controller->Form()->Actions()->Count(), 1);
- $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0);
+ // test form
+ $this->assertEquals($controller->Form()->getName(), 'Form', 'The form is referenced as Form');
+ $this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
+ $this->assertEquals($controller->Form()->Actions()->Count(), 1);
+ $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 0);
- $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
- $controller = new UserDefinedFormControllerTest_Controller($requiredForm);
+ $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
+ $controller = new UserDefinedFormControllerTest_Controller($requiredForm);
- $this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
- $this->assertEquals($controller->Form()->Actions()->Count(), 1);
- $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
- }
+ $this->assertEquals($controller->Form()->Fields()->Count(), 1); // disabled SecurityID token fields
+ $this->assertEquals($controller->Form()->Actions()->Count(), 1);
+ $this->assertEquals(count($controller->Form()->getValidator()->getRequired()), 1);
+ }
- public function testGetFormFields() {
- // generating the fieldset of fields
- $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ public function testGetFormFields()
+ {
+ // generating the fieldset of fields
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
- $controller = new UserDefinedFormControllerTest_Controller($form);
+ $controller = new UserDefinedFormControllerTest_Controller($form);
+
+ $formSteps = $controller->Form()->getFormFields();
+ $firstStep = $formSteps->first();
- $formSteps = $controller->Form()->getFormFields();
- $firstStep = $formSteps->first();
+ $this->assertEquals($formSteps->Count(), 1);
+ $this->assertEquals($firstStep->getChildren()->Count(), 1);
- $this->assertEquals($formSteps->Count(), 1);
- $this->assertEquals($firstStep->getChildren()->Count(), 1);
+ // custom error message on a form field
+ $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
+ $controller = new UserDefinedFormControllerTest_Controller($requiredForm);
- // custom error message on a form field
- $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form');
- $controller = new UserDefinedFormControllerTest_Controller($requiredForm);
+ UserDefinedForm::config()->required_identifier = "*";
- UserDefinedForm::config()->required_identifier = "*";
+ $formSteps = $controller->Form()->getFormFields();
+ $firstStep = $formSteps->first();
+ $firstField = $firstStep->getChildren()->first();
- $formSteps = $controller->Form()->getFormFields();
- $firstStep = $formSteps->first();
- $firstField = $firstStep->getChildren()->first();
+ $this->assertEquals('Custom Error Message', $firstField->getCustomValidationMessage());
+ $this->assertEquals($firstField->Title(), 'Required Text Field *');
- $this->assertEquals('Custom Error Message', $firstField->getCustomValidationMessage());
- $this->assertEquals($firstField->Title(), 'Required Text Field *');
+ // test custom right title
+ $field = $form->Fields()->limit(1, 1)->First();
+ $field->RightTitle = 'Right Title';
+ $field->write();
- // test custom right title
- $field = $form->Fields()->limit(1, 1)->First();
- $field->RightTitle = 'Right Title';
- $field->write();
+ $controller = new UserDefinedFormControllerTest_Controller($form);
+ $formSteps = $controller->Form()->getFormFields();
+ $firstStep = $formSteps->first();
- $controller = new UserDefinedFormControllerTest_Controller($form);
- $formSteps = $controller->Form()->getFormFields();
- $firstStep = $formSteps->first();
+ $this->assertEquals($firstStep->getChildren()->First()->RightTitle(), "Right Title");
- $this->assertEquals($firstStep->getChildren()->First()->RightTitle(), "Right Title");
+ // test empty form
+ $emptyForm = $this->objFromFixture('UserDefinedForm', 'empty-form');
+ $controller = new UserDefinedFormControllerTest_Controller($emptyForm);
- // test empty form
- $emptyForm = $this->objFromFixture('UserDefinedForm', 'empty-form');
- $controller = new UserDefinedFormControllerTest_Controller($emptyForm);
+ $this->assertFalse($controller->Form()->getFormFields()->exists());
+ }
- $this->assertFalse($controller->Form()->getFormFields()->exists());
- }
+ public function testGetFormActions()
+ {
+ // generating the fieldset of actions
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
- public function testGetFormActions()
- {
- // generating the fieldset of actions
- $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ $controller = new UserDefinedFormControllerTest_Controller($form);
+ $actions = $controller->Form()->getFormActions();
- $controller = new UserDefinedFormControllerTest_Controller($form);
- $actions = $controller->Form()->getFormActions();
+ // by default will have 1 submit button which links to process
+ $expected = new FieldList(new FormAction('process', 'Submit'));
+ $expected->setForm($controller->Form());
- // by default will have 1 submit button which links to process
- $expected = new FieldList(new FormAction('process', 'Submit'));
- $expected->setForm($controller->Form());
+ $this->assertEquals($actions, $expected);
- $this->assertEquals($actions, $expected);
+ // the custom popup should have a reset button and a custom text
+ $custom = $this->objFromFixture('UserDefinedForm', 'form-with-reset-and-custom-action');
+ $controller = new UserDefinedFormControllerTest_Controller($custom);
+ $actions = $controller->Form()->getFormActions();
- // the custom popup should have a reset button and a custom text
- $custom = $this->objFromFixture('UserDefinedForm', 'form-with-reset-and-custom-action');
- $controller = new UserDefinedFormControllerTest_Controller($custom);
- $actions = $controller->Form()->getFormActions();
+ $expected = new FieldList(new FormAction('process', 'Custom Button'));
+ $expected->push(new ResetFormAction("clearForm", "Clear"));
+ $expected->setForm($controller->Form());
- $expected = new FieldList(new FormAction('process', 'Custom Button'));
- $expected->push(new ResetFormAction("clearForm", "Clear"));
- $expected->setForm($controller->Form());
+ $this->assertEquals($actions, $expected);
+ }
- $this->assertEquals($actions, $expected);
- }
+ public function testRenderingIntoFormTemplate()
+ {
+ $form = $this->setupFormFrontend();
- public function testRenderingIntoFormTemplate() {
- $form = $this->setupFormFrontend();
+ $form->Content = 'This is some content without a form nested between it';
+ $form->doPublish();
- $form->Content = 'This is some content without a form nested between it';
- $form->doPublish();
+ $controller = new UserDefinedFormControllerTest_Controller($form);
- $controller = new UserDefinedFormControllerTest_Controller($form);
+ // check to see if $Form is replaced to inside the content
+ $index = new ArrayData($controller->index());
+ $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
- // check to see if $Form is replaced to inside the content
- $index = new ArrayData($controller->index());
- $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
+ $this->checkTemplateIsCorrect($parser);
+ }
- $this->checkTemplateIsCorrect($parser);
- }
+ public function testRenderingIntoTemplateWithSubstringReplacement()
+ {
+ $form = $this->setupFormFrontend();
- public function testRenderingIntoTemplateWithSubstringReplacement() {
- $form = $this->setupFormFrontend();
+ $controller = new UserDefinedFormControllerTest_Controller($form);
- $controller = new UserDefinedFormControllerTest_Controller($form);
+ // check to see if $Form is replaced to inside the content
+ $index = new ArrayData($controller->index());
+ $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
- // check to see if $Form is replaced to inside the content
- $index = new ArrayData($controller->index());
- $parser = new CSSContentParser($index->renderWith(array('UserDefinedFormControllerTest')));
+ $this->checkTemplateIsCorrect($parser);
+ }
+ /**
+ * Publish a form for use on the frontend
+ *
+ * @param string $fixtureName
+ * @return UserDefinedForm
+ */
+ protected function setupFormFrontend($fixtureName = 'basic-form-page')
+ {
+ $form = $this->objFromFixture('UserDefinedForm', $fixtureName);
+ $this->logInWithPermission('ADMIN');
- $this->checkTemplateIsCorrect($parser);
- }
- /**
- * Publish a form for use on the frontend
- *
- * @param string $fixtureName
- * @return UserDefinedForm
- */
- protected function setupFormFrontend($fixtureName = 'basic-form-page') {
- $form = $this->objFromFixture('UserDefinedForm', $fixtureName);
- $this->logInWithPermission('ADMIN');
+ $form->doPublish();
- $form->doPublish();
+ $member = Member::currentUser();
+ $member->logOut();
- $member = Member::currentUser();
- $member->logOut();
+ return $form;
+ }
- return $form;
- }
+ public function checkTemplateIsCorrect($parser)
+ {
+ $this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form'));
- public function checkTemplateIsCorrect($parser) {
- $this->assertArrayHasKey(0, $parser->getBySelector('form#UserForm_Form'));
+ // check for the input
+ $this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
- // check for the input
- $this->assertArrayHasKey(0, $parser->getBySelector('input.text'));
+ // check for the label and the text
+ $label = $parser->getBySelector('label.left');
+ $this->assertArrayHasKey(0, $label);
- // check for the label and the text
- $label = $parser->getBySelector('label.left');
- $this->assertArrayHasKey(0, $label);
+ $this->assertEquals((string) $label[0][0], "Basic Text Field", "Label contains correct field name");
- $this->assertEquals((string) $label[0][0], "Basic Text Field", "Label contains correct field name");
+ // check for the action
+ $action = $parser->getBySelector('input.action');
+ $this->assertArrayHasKey(0, $action);
- // check for the action
- $action = $parser->getBySelector('input.action');
- $this->assertArrayHasKey(0, $action);
-
- $this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
- }
+ $this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
+ }
}
-class UserDefinedFormControllerTest_Controller extends UserDefinedForm_Controller implements TestOnly {
+class UserDefinedFormControllerTest_Controller extends UserDefinedForm_Controller implements TestOnly
+{
- /**
- * Overloaded to avoid inconsistencies between 2.4.2 and 2.4.3 (disables all security tokens in unit tests by default)
- */
- public function Form() {
- $form = parent::Form();
+ /**
+ * Overloaded to avoid inconsistencies between 2.4.2 and 2.4.3 (disables all security tokens in unit tests by default)
+ */
+ public function Form()
+ {
+ $form = parent::Form();
- if($form) $form->disableSecurityToken();
-
- return $form;
- }
+ if ($form) {
+ $form->disableSecurityToken();
+ }
+ return $form;
+ }
}
diff --git a/tests/UserDefinedFormTest.php b/tests/UserDefinedFormTest.php
index c418563..f9d06a7 100644
--- a/tests/UserDefinedFormTest.php
+++ b/tests/UserDefinedFormTest.php
@@ -3,421 +3,436 @@
/**
* @package userforms
*/
-class UserDefinedFormTest extends FunctionalTest {
+class UserDefinedFormTest extends FunctionalTest
+{
- static $fixture_file = 'UserDefinedFormTest.yml';
+ public static $fixture_file = 'UserDefinedFormTest.yml';
- public function testRollbackToVersion() {
- $this->markTestSkipped(
- 'UserDefinedForm::rollback() has not been implemented completely'
- );
+ public function testRollbackToVersion()
+ {
+ $this->markTestSkipped(
+ 'UserDefinedForm::rollback() has not been implemented completely'
+ );
- // @todo
- $this->logInWithPermission('ADMIN');
- $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ // @todo
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
- $form->SubmitButtonText = 'Button Text';
- $form->write();
- $form->doPublish();
- $origVersion = $form->Version;
+ $form->SubmitButtonText = 'Button Text';
+ $form->write();
+ $form->doPublish();
+ $origVersion = $form->Version;
- $form->SubmitButtonText = 'Updated Button Text';
- $form->write();
- $form->doPublish();
+ $form->SubmitButtonText = 'Updated Button Text';
+ $form->write();
+ $form->doPublish();
- // check published site
- $updated = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
- $this->assertEquals($updated->SubmitButtonText, 'Updated Button Text');
+ // check published site
+ $updated = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
+ $this->assertEquals($updated->SubmitButtonText, 'Updated Button Text');
- $form->doRollbackTo($origVersion);
+ $form->doRollbackTo($origVersion);
- $orignal = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
- $this->assertEquals($orignal->SubmitButtonText, 'Button Text');
- }
+ $orignal = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID");
+ $this->assertEquals($orignal->SubmitButtonText, 'Button Text');
+ }
- public function testGetCMSFields() {
- $this->logInWithPermission('ADMIN');
- $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ public function testGetCMSFields()
+ {
+ $this->logInWithPermission('ADMIN');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
- $fields = $form->getCMSFields();
+ $fields = $form->getCMSFields();
- $this->assertTrue($fields->dataFieldByName('Fields') !== null);
- $this->assertTrue($fields->dataFieldByName('EmailRecipients') != null);
- $this->assertTrue($fields->dataFieldByName('Submissions') != null);
- $this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
- }
+ $this->assertTrue($fields->dataFieldByName('Fields') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailRecipients') != null);
+ $this->assertTrue($fields->dataFieldByName('Submissions') != null);
+ $this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
+ }
- public function testEmailRecipientPopup() {
- $this->logInWithPermission('ADMIN');
+ public function testEmailRecipientPopup()
+ {
+ $this->logInWithPermission('ADMIN');
- $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
+ $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
- $popup = new UserDefinedForm_EmailRecipient();
- $popup->FormID = $form->ID;
+ $popup = new UserDefinedForm_EmailRecipient();
+ $popup->FormID = $form->ID;
- $fields = $popup->getCMSFields();
+ $fields = $popup->getCMSFields();
- $this->assertTrue($fields->dataFieldByName('EmailSubject') !== null);
- $this->assertTrue($fields->dataFieldByName('EmailFrom') !== null);
- $this->assertTrue($fields->dataFieldByName('EmailAddress') !== null);
- $this->assertTrue($fields->dataFieldByName('HideFormData') !== null);
- $this->assertTrue($fields->dataFieldByName('SendPlain') !== null);
- $this->assertTrue($fields->dataFieldByName('EmailBody') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailSubject') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailFrom') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailAddress') !== null);
+ $this->assertTrue($fields->dataFieldByName('HideFormData') !== null);
+ $this->assertTrue($fields->dataFieldByName('SendPlain') !== null);
+ $this->assertTrue($fields->dataFieldByName('EmailBody') !== null);
- // add an email field, it should now add a or from X address picker
- $email = $this->objFromFixture('EditableEmailField','email-field');
- $form->Fields()->add($email);
+ // add an email field, it should now add a or from X address picker
+ $email = $this->objFromFixture('EditableEmailField', 'email-field');
+ $form->Fields()->add($email);
- $popup->write();
+ $popup->write();
- $fields = $popup->getCMSFields();
- $this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField'));
+ $fields = $popup->getCMSFields();
+ $this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField'));
- // if the front end has checkboxs or dropdown they can select from that can also be used to send things
- $dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown');
- $form->Fields()->add($dropdown);
+ // if the front end has checkboxs or dropdown they can select from that can also be used to send things
+ $dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown');
+ $form->Fields()->add($dropdown);
- $fields = $popup->getCMSFields();
- $this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null);
+ $fields = $popup->getCMSFields();
+ $this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null);
- $popup->delete();
- }
+ $popup->delete();
+ }
- function testGetEmailBodyContent() {
- $recipient = new UserDefinedForm_EmailRecipient();
+ public function testGetEmailBodyContent()
+ {
+ $recipient = new UserDefinedForm_EmailRecipient();
- $emailBody = 'not html';
- $emailBodyHtml = '