mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Update core API changes, implement last of namespacing in test classes, PSR-4 autoloader
This commit is contained in:
parent
32586b6363
commit
5af348894a
@ -4,4 +4,4 @@ After: framework/routes#coreroutes
|
|||||||
---
|
---
|
||||||
SilverStripe\Control\Director:
|
SilverStripe\Control\Director:
|
||||||
rules:
|
rules:
|
||||||
UserDefinedForm_Controller//$Action: UserDefinedForm_Controller
|
UserDefinedFormController//$Action: SilverStripe\UserForms\Model\UserDefinedFormController
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\UserForms\Extension;
|
namespace SilverStripe\UserForms\Extension;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Tab;
|
use SilverStripe\Forms\Tab;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
@ -28,7 +29,6 @@ use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
|
|||||||
*/
|
*/
|
||||||
class UserFormFieldEditorExtension extends DataExtension
|
class UserFormFieldEditorExtension extends DataExtension
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -58,7 +58,8 @@ class UserFormFieldEditorExtension extends DataExtension
|
|||||||
*/
|
*/
|
||||||
public function getFieldEditorGrid()
|
public function getFieldEditorGrid()
|
||||||
{
|
{
|
||||||
Requirements::javascript(USERFORMS_DIR . '/javascript/FieldEditor.js');
|
$module = ModuleLoader::getModule('silverstripe/userforms');
|
||||||
|
Requirements::javascript($module->getRelativeResourcePath('javascript/FieldEditor.js'));
|
||||||
|
|
||||||
$fields = $this->owner->Fields();
|
$fields = $this->owner->Fields();
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ class UserFormFieldEditorExtension extends DataExtension
|
|||||||
|
|
||||||
$editableColumns = new GridFieldEditableColumns();
|
$editableColumns = new GridFieldEditableColumns();
|
||||||
$fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses();
|
$fieldClasses = singleton(EditableFormField::class)->getEditableFieldClasses();
|
||||||
$editableColumns->setDisplayFields(array(
|
$editableColumns->setDisplayFields([
|
||||||
'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
|
'ClassName' => function ($record, $column, $grid) use ($fieldClasses) {
|
||||||
if ($record instanceof EditableFormField) {
|
if ($record instanceof EditableFormField) {
|
||||||
return $record->getInlineClassnameField($column, $fieldClasses);
|
return $record->getInlineClassnameField($column, $fieldClasses);
|
||||||
@ -77,18 +78,18 @@ class UserFormFieldEditorExtension extends DataExtension
|
|||||||
return $record->getInlineTitleField($column);
|
return $record->getInlineTitleField($column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
]);
|
||||||
|
|
||||||
$config = GridFieldConfig::create()
|
$config = GridFieldConfig::create()
|
||||||
->addComponents(
|
->addComponents(
|
||||||
$editableColumns,
|
$editableColumns,
|
||||||
new GridFieldButtonRow(),
|
new GridFieldButtonRow(),
|
||||||
GridFieldAddClassesButton::create(EditableTextField::class)
|
(new GridFieldAddClassesButton(EditableTextField::class))
|
||||||
->setButtonName(_t(__CLASS__.'.ADD_FIELD', 'Add Field'))
|
->setButtonName(_t(__CLASS__.'.ADD_FIELD', 'Add Field'))
|
||||||
->setButtonClass('ss-ui-action-constructive'),
|
->setButtonClass('ss-ui-action-constructive'),
|
||||||
GridFieldAddClassesButton::create(EditableFormStep::class)
|
(new GridFieldAddClassesButton(EditableFormStep::class))
|
||||||
->setButtonName(_t(__CLASS__.'.ADD_PAGE_BREAK', 'Add Page Break')),
|
->setButtonName(_t(__CLASS__.'.ADD_PAGE_BREAK', 'Add Page Break')),
|
||||||
GridFieldAddClassesButton::create(array(EditableFieldGroup::class, EditableFieldGroupEnd::class))
|
(new GridFieldAddClassesButton([EditableFieldGroup::class, EditableFieldGroupEnd::class]))
|
||||||
->setButtonName(_t(__CLASS__.'.ADD_FIELD_GROUP', 'Add Field Group')),
|
->setButtonName(_t(__CLASS__.'.ADD_FIELD_GROUP', 'Add Field Group')),
|
||||||
new GridFieldEditButton(),
|
new GridFieldEditButton(),
|
||||||
new GridFieldDeleteAction(),
|
new GridFieldDeleteAction(),
|
||||||
@ -165,6 +166,10 @@ class UserFormFieldEditorExtension extends DataExtension
|
|||||||
*/
|
*/
|
||||||
public function onAfterPublish($original)
|
public function onAfterPublish($original)
|
||||||
{
|
{
|
||||||
|
if (!$original) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// store IDs of fields we've published
|
// store IDs of fields we've published
|
||||||
$seenIDs = array();
|
$seenIDs = array();
|
||||||
|
|
||||||
@ -177,14 +182,14 @@ class UserFormFieldEditorExtension extends DataExtension
|
|||||||
|
|
||||||
// fetch any orphaned live records
|
// fetch any orphaned live records
|
||||||
$live = Versioned::get_by_stage(EditableFormField::class, "Live")
|
$live = Versioned::get_by_stage(EditableFormField::class, "Live")
|
||||||
->filter(array(
|
->filter([
|
||||||
'ParentID' => $original->ID,
|
'ParentID' => $original->ID,
|
||||||
));
|
]);
|
||||||
|
|
||||||
if (!empty($seenIDs)) {
|
if (!empty($seenIDs)) {
|
||||||
$live = $live->exclude(array(
|
$live = $live->exclude([
|
||||||
'ID' => $seenIDs,
|
'ID' => $seenIDs,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete orphaned records
|
// delete orphaned records
|
||||||
|
@ -48,7 +48,6 @@ class GridFieldAddClassesButton implements GridField_HTMLProvider, GridField_Act
|
|||||||
*/
|
*/
|
||||||
public function __construct($classes, $targetFragment = 'buttons-before-left')
|
public function __construct($classes, $targetFragment = 'buttons-before-left')
|
||||||
{
|
{
|
||||||
parent::__construct();
|
|
||||||
$this->setClasses($classes);
|
$this->setClasses($classes);
|
||||||
$this->setFragment($targetFragment);
|
$this->setFragment($targetFragment);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class UserForm extends Form
|
|||||||
$this->setValidator($this->getRequiredFields());
|
$this->setValidator($this->getRequiredFields());
|
||||||
|
|
||||||
// This needs to be re-evaluated since fields have been assigned
|
// This needs to be re-evaluated since fields have been assigned
|
||||||
$this->setupFormErrors();
|
$this->restoreFormState();
|
||||||
|
|
||||||
// Number each page
|
// Number each page
|
||||||
$stepNumber = 1;
|
$stepNumber = 1;
|
||||||
@ -52,7 +52,7 @@ class UserForm extends Form
|
|||||||
$this->disableSecurityToken();
|
$this->disableSecurityToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = Session::get("FormInfo.{$this->FormName()}.data");
|
$data = $this->getRequest()->getSession()->get("FormInfo.{$this->FormName()}.data");
|
||||||
|
|
||||||
if (is_array($data)) {
|
if (is_array($data)) {
|
||||||
$this->loadDataFrom($data);
|
$this->loadDataFrom($data);
|
||||||
@ -61,11 +61,11 @@ class UserForm extends Form
|
|||||||
$this->extend('updateForm');
|
$this->extend('updateForm');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setupFormErrors()
|
public function restoreFormState()
|
||||||
{
|
{
|
||||||
// Suppress setupFormErrors if fields haven't been bootstrapped
|
// Suppress restoreFormState if fields haven't been bootstrapped
|
||||||
if ($this->fields && $this->fields->exists()) {
|
if ($this->fields && $this->fields->exists()) {
|
||||||
return parent::setupFormErrors();
|
return parent::restoreFormState();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -134,15 +134,17 @@ class UserForm extends Form
|
|||||||
*/
|
*/
|
||||||
public function getFormActions()
|
public function getFormActions()
|
||||||
{
|
{
|
||||||
$submitText = ($this->controller->SubmitButtonText) ? $this->controller->SubmitButtonText : _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMITBUTTON', 'Submit');
|
$submitText = ($this->controller->SubmitButtonText)
|
||||||
$clearText = ($this->controller->ClearButtonText) ? $this->controller->ClearButtonText : _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CLEARBUTTON', 'Clear');
|
? $this->controller->SubmitButtonText
|
||||||
|
: _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMITBUTTON', 'Submit');
|
||||||
|
$clearText = ($this->controller->ClearButtonText)
|
||||||
|
? $this->controller->ClearButtonText
|
||||||
|
: _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CLEARBUTTON', 'Clear');
|
||||||
|
|
||||||
$actions = new FieldList(
|
$actions = FieldList::create(FormAction::create('process', $submitText));
|
||||||
new FormAction("process", $submitText)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($this->controller->ShowClearButton) {
|
if ($this->controller->ShowClearButton) {
|
||||||
$actions->push(new ResetFormAction("clearForm", $clearText));
|
$actions->push(FormAction::create('clearForm', $clearText)->setAttribute('type', 'reset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('updateFormActions', $actions);
|
$this->extend('updateFormActions', $actions);
|
||||||
|
@ -8,6 +8,7 @@ use SilverStripe\Control\Controller;
|
|||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Dev\Deprecation;
|
use SilverStripe\Dev\Deprecation;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
@ -422,8 +423,9 @@ class EditableFormField extends DataObject
|
|||||||
protected function generateName()
|
protected function generateName()
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
// Generate a new random name after this class
|
// Generate a new random name after this class (handles namespaces)
|
||||||
$class = get_class($this);
|
$classNamePieces = explode('\\', __CLASS__);
|
||||||
|
$class = array_pop($classNamePieces);
|
||||||
$entropy = substr(sha1(uniqid()), 0, 5);
|
$entropy = substr(sha1(uniqid()), 0, 5);
|
||||||
$name = "{$class}_{$entropy}";
|
$name = "{$class}_{$entropy}";
|
||||||
|
|
||||||
@ -730,7 +732,8 @@ class EditableFormField extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function getIcon()
|
public function getIcon()
|
||||||
{
|
{
|
||||||
return USERFORMS_DIR . '/images/' . strtolower($this->class) . '.png';
|
return ModuleLoader::getModule('silverstripe/userforms')
|
||||||
|
->getRelativeResourcePath('images/' . strtolower($this->class) . '.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\UserForms\Model\EditableFormField;
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use CountryDropdownField; // @todo
|
use CountryDropdownField; // @todo
|
||||||
use SilverStripe\UserForms\Model\EditableCustomRule;
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField;
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
@ -52,7 +53,8 @@ class EditableCountryDropdownField extends EditableFormField
|
|||||||
|
|
||||||
public function getIcon()
|
public function getIcon()
|
||||||
{
|
{
|
||||||
return USERFORMS_DIR . '/images/editabledropdown.png';
|
return ModuleLoader::getModule('silverstripe/userforms')
|
||||||
|
->getRelativeResourcePath('images/editabledropdown.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
||||||
|
@ -89,7 +89,7 @@ class EditableFileField extends EditableFormField
|
|||||||
|
|
||||||
$max = static::get_php_max_file_size();
|
$max = static::get_php_max_file_size();
|
||||||
if ($this->MaxFileSizeMB * 1024 > $max) {
|
if ($this->MaxFileSizeMB * 1024 > $max) {
|
||||||
$result->error("Your max file size limit can't be larger than the server's limit of {$this->getPHPMaxFileSizeMB()}.");
|
$result->addError("Your max file size limit can't be larger than the server's limit of {$this->getPHPMaxFileSizeMB()}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -144,7 +144,7 @@ class EditableLiteralField extends EditableFormField
|
|||||||
|
|
||||||
$field = CompositeField::create($content)
|
$field = CompositeField::create($content)
|
||||||
->setName($this->Name)
|
->setName($this->Name)
|
||||||
->setID($this->Name)
|
// ->setID($this->Name) // @todo
|
||||||
->setFieldHolderTemplate('UserFormsLiteralField_holder');
|
->setFieldHolderTemplate('UserFormsLiteralField_holder');
|
||||||
|
|
||||||
$this->doUpdateFormField($field);
|
$this->doUpdateFormField($field);
|
||||||
|
@ -8,6 +8,7 @@ use SilverStripe\CMS\Controllers\CMSPageEditController;
|
|||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\Email\Email;
|
use SilverStripe\Control\Email\Email;
|
||||||
use SilverStripe\Control\Session;
|
use SilverStripe\Control\Session;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\FieldGroup;
|
use SilverStripe\Forms\FieldGroup;
|
||||||
@ -164,7 +165,9 @@ class EmailRecipient extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
Requirements::javascript(USERFORMS_DIR . '/javascript/Recipient.js');
|
Requirements::javascript(
|
||||||
|
ModuleLoader::getModule('silverstripe/userforms')->getRelativeResourcePath('javascript/Recipient.js')
|
||||||
|
);
|
||||||
|
|
||||||
// Determine optional field values
|
// Determine optional field values
|
||||||
$form = $this->getFormParent();
|
$form = $this->getFormParent();
|
||||||
@ -281,7 +284,7 @@ class EmailRecipient extends DataObject
|
|||||||
))
|
))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fields->fieldByName('Root.EmailDetails')->setTitle(_t(__CLASS.'.EMAILDETAILSTAB', 'Email Details'));
|
$fields->fieldByName('Root.EmailDetails')->setTitle(_t(__CLASS__.'.EMAILDETAILSTAB', 'Email Details'));
|
||||||
|
|
||||||
// Only show the preview link if the recipient has been saved.
|
// Only show the preview link if the recipient has been saved.
|
||||||
if (!empty($this->EmailTemplate)) {
|
if (!empty($this->EmailTemplate)) {
|
||||||
@ -338,7 +341,7 @@ class EmailRecipient extends DataObject
|
|||||||
LiteralField::create('EmailPreview', $preview)
|
LiteralField::create('EmailPreview', $preview)
|
||||||
));
|
));
|
||||||
|
|
||||||
$fields->fieldByName('Root.EmailContent')->setTitle(_t(__CLASS.'.EMAILCONTENTTAB', 'Email Content'));
|
$fields->fieldByName('Root.EmailContent')->setTitle(_t(__CLASS__.'.EMAILCONTENTTAB', 'Email Content'));
|
||||||
|
|
||||||
// Custom rules for sending this field
|
// Custom rules for sending this field
|
||||||
$grid = GridField::create(
|
$grid = GridField::create(
|
||||||
@ -363,7 +366,7 @@ class EmailRecipient extends DataObject
|
|||||||
$grid
|
$grid
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$fields->fieldByName('Root.CustomRules')->setTitle(_t(__CLASS.'.CUSTOMRULESTAB', 'Custom Rules'));
|
$fields->fieldByName('Root.CustomRules')->setTitle(_t(__CLASS__.'.CUSTOMRULESTAB', 'Custom Rules'));
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
$this->extend('updateCMSFields', $fields);
|
||||||
return $fields;
|
return $fields;
|
||||||
@ -542,7 +545,7 @@ class EmailRecipient extends DataObject
|
|||||||
$trimAddress = trim($address);
|
$trimAddress = trim($address);
|
||||||
if ($trimAddress && !Email::is_valid_address($trimAddress)) {
|
if ($trimAddress && !Email::is_valid_address($trimAddress)) {
|
||||||
$error = _t(
|
$error = _t(
|
||||||
__CLASS.".$translation",
|
__CLASS__.".$translation",
|
||||||
"Invalid email address $trimAddress"
|
"Invalid email address $trimAddress"
|
||||||
);
|
);
|
||||||
$result->error($error . " ($trimAddress)");
|
$result->error($error . " ($trimAddress)");
|
||||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\UserForms\Model;
|
|||||||
use Page;
|
use Page;
|
||||||
use Colymba\BulkManager\BulkManager;
|
use Colymba\BulkManager\BulkManager;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\CompositeField;
|
use SilverStripe\Forms\CompositeField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -171,7 +172,9 @@ class UserDefinedForm extends Page
|
|||||||
*/
|
*/
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
Requirements::css(USERFORMS_DIR . '/css/UserForm_cms.css');
|
Requirements::css(
|
||||||
|
ModuleLoader::getModule('silverstripe/userforms')->getRelativeResourcePath('css/UserForms_cms.css')
|
||||||
|
);
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function ($fields) {
|
||||||
// define tabs
|
// define tabs
|
||||||
@ -181,8 +184,15 @@ class UserDefinedForm extends Page
|
|||||||
|
|
||||||
// text to show on complete
|
// text to show on complete
|
||||||
$onCompleteFieldSet = CompositeField::create(
|
$onCompleteFieldSet = CompositeField::create(
|
||||||
$label = LabelField::create('OnCompleteMessageLabel', _t(__CLASS__.'.ONCOMPLETELABEL', 'Show on completion')),
|
$label = LabelField::create(
|
||||||
$editor = HTMLEditorField::create('OnCompleteMessage', '', _t(__CLASS__.'.ONCOMPLETEMESSAGE', $self->OnCompleteMessage))
|
'OnCompleteMessageLabel',
|
||||||
|
_t(__CLASS__.'.ONCOMPLETELABEL', 'Show on completion')
|
||||||
|
),
|
||||||
|
$editor = HTMLEditorField::create(
|
||||||
|
'OnCompleteMessage',
|
||||||
|
'',
|
||||||
|
_t(__CLASS__.'.ONCOMPLETEMESSAGE', $this->OnCompleteMessage)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$onCompleteFieldSet->addExtraClass('field');
|
$onCompleteFieldSet->addExtraClass('field');
|
||||||
@ -201,7 +211,7 @@ class UserDefinedForm extends Page
|
|||||||
$emailRecipients = GridField::create(
|
$emailRecipients = GridField::create(
|
||||||
'EmailRecipients',
|
'EmailRecipients',
|
||||||
_t(__CLASS__.'.EMAILRECIPIENTS', 'Email Recipients'),
|
_t(__CLASS__.'.EMAILRECIPIENTS', 'Email Recipients'),
|
||||||
$self->EmailRecipients(),
|
$this->EmailRecipients(),
|
||||||
$emailRecipientsConfig
|
$emailRecipientsConfig
|
||||||
);
|
);
|
||||||
$emailRecipients
|
$emailRecipients
|
||||||
@ -211,12 +221,12 @@ class UserDefinedForm extends Page
|
|||||||
|
|
||||||
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
|
$fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet);
|
||||||
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
|
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
|
||||||
$fields->addFieldsToTab('Root.FormOptions', $self->getFormOptions());
|
$fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions());
|
||||||
|
|
||||||
|
|
||||||
// view the submissions
|
// view the submissions
|
||||||
// make sure a numeric not a empty string is checked against this int column for SQL server
|
// 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;
|
$parentID = (!empty($this->ID)) ? (int) $this->ID : 0;
|
||||||
|
|
||||||
// get a list of all field names and values used for print and export CSV views of the GridField below.
|
// get a list of all field names and values used for print and export CSV views of the GridField below.
|
||||||
$columnSQL = <<<SQL
|
$columnSQL = <<<SQL
|
||||||
@ -289,7 +299,7 @@ SQL;
|
|||||||
$submissions = GridField::create(
|
$submissions = GridField::create(
|
||||||
'Submissions',
|
'Submissions',
|
||||||
_t(__CLASS__.'.SUBMISSIONS', 'Submissions'),
|
_t(__CLASS__.'.SUBMISSIONS', 'Submissions'),
|
||||||
$self->Submissions()->sort('Created', 'DESC'),
|
$this->Submissions()->sort('Created', 'DESC'),
|
||||||
$config
|
$config
|
||||||
);
|
);
|
||||||
$fields->addFieldToTab('Root.Submissions', $submissions);
|
$fields->addFieldToTab('Root.Submissions', $submissions);
|
||||||
@ -377,23 +387,6 @@ SQL;
|
|||||||
return $this->config()->get('error_container_id');
|
return $this->config()->get('error_container_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requireDefaultRecords()
|
|
||||||
{
|
|
||||||
parent::requireDefaultRecords();
|
|
||||||
|
|
||||||
if (!$this->config()->get('upgrade_on_build')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform migrations
|
|
||||||
Injector::inst()
|
|
||||||
->create(UserFormsUpgradeService::class)
|
|
||||||
->setQuiet(true)
|
|
||||||
->run();
|
|
||||||
|
|
||||||
DB::alteration_message('Migrated userforms', 'changed');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate formfields
|
* Validate formfields
|
||||||
|
@ -7,6 +7,7 @@ use SilverStripe\Assets\File;
|
|||||||
use SilverStripe\Assets\Upload;
|
use SilverStripe\Assets\Upload;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\HTTP;
|
use SilverStripe\Control\HTTP;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\i18n\i18n;
|
use SilverStripe\i18n\i18n;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
@ -43,29 +44,37 @@ class UserDefinedFormController extends PageController
|
|||||||
|
|
||||||
$page = $this->data();
|
$page = $this->data();
|
||||||
|
|
||||||
|
$userforms = ModuleLoader::getModule('silverstripe/userforms');
|
||||||
|
$admin = ModuleLoader::getModule('silverstripe/admin');
|
||||||
// load the css
|
// load the css
|
||||||
if (!$page->config()->get('block_default_userforms_css')) {
|
if (!$page->config()->get('block_default_userforms_css')) {
|
||||||
Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
|
Requirements::css($userforms->getRelativeResourcePath('css/UserForm.css'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the jquery
|
// load the jquery
|
||||||
if (!$page->config()->get('block_default_userforms_js')) {
|
if (!$page->config()->get('block_default_userforms_js')) {
|
||||||
$lang = i18n::get_lang_from_locale(i18n::get_locale());
|
$lang = i18n::getData()->languageName(i18n::get_locale());
|
||||||
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($admin->getRelativeResourcePath('thirdparty/jquery/jquery.js'));
|
||||||
Requirements::javascript(
|
Requirements::javascript(
|
||||||
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js"
|
$userforms->getRelativeResourcePath('thirdparty/jquery-validate/jquery.validate.min.js')
|
||||||
);
|
|
||||||
Requirements::javascript(
|
|
||||||
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
|
|
||||||
);
|
);
|
||||||
|
Requirements::add_i18n_javascript($userforms->getRelativeResourcePath('javascript/lang'));
|
||||||
|
Requirements::javascript($userforms->getRelativeResourcePath('javascript/UserForm.js'));
|
||||||
|
|
||||||
|
// @todo implement the $lang correctly
|
||||||
|
// Requirements::javascript(
|
||||||
|
// $userforms->getRelativeResourcePath("thirdparty/jquery-validate/localization/messages_{$lang}.min.js")
|
||||||
|
// );
|
||||||
|
// Requirements::javascript(
|
||||||
|
// $userforms->getRelativeResourcePath("thirdparty/jquery-validate/localization/methods_{$lang}.min.js")
|
||||||
|
// );
|
||||||
|
|
||||||
// Bind a confirmation message when navigating away from a partially completed form.
|
// Bind a confirmation message when navigating away from a partially completed form.
|
||||||
if ($page::config()->get('enable_are_you_sure')) {
|
if ($page::config()->get('enable_are_you_sure')) {
|
||||||
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
|
Requirements::javascript(
|
||||||
|
$userforms->getRelativeResourcePath('thirdparty/jquery.are-you-sure/jquery.are-you-sure.js')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +91,11 @@ class UserDefinedFormController extends PageController
|
|||||||
if ($this->Content && $form = $this->Form()) {
|
if ($this->Content && $form = $this->Form()) {
|
||||||
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
||||||
if ($hasLocation) {
|
if ($hasLocation) {
|
||||||
$content = preg_replace('/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
|
$content = preg_replace(
|
||||||
|
'/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i',
|
||||||
|
$form->forTemplate(),
|
||||||
|
$this->Content
|
||||||
|
);
|
||||||
return [
|
return [
|
||||||
'Content' => DBField::create_field('HTMLText', $content),
|
'Content' => DBField::create_field('HTMLText', $content),
|
||||||
'Form' => ''
|
'Form' => ''
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
"phpunit/phpunit": "^5.7",
|
"phpunit/phpunit": "^5.7",
|
||||||
"squizlabs/php_codesniffer": "*"
|
"squizlabs/php_codesniffer": "*"
|
||||||
},
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"SilverStripe\\UserForms\\": "code/",
|
||||||
|
"SilverStripe\\UserForms\\Test\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"colymba/gridfield-bulk-editing-tools": "Allows for bulk management of form submissions",
|
"colymba/gridfield-bulk-editing-tools": "Allows for bulk management of form submissions",
|
||||||
"silverstripe/secureassets": "Enables files uploaded via userforms to be secured from public access",
|
"silverstripe/secureassets": "Enables files uploaded via userforms to be secured from public access",
|
||||||
|
@ -9,7 +9,7 @@ use SilverStripe\UserForms\Form\UserForm;
|
|||||||
|
|
||||||
class UserFormTest extends SapphireTest
|
class UserFormTest extends SapphireTest
|
||||||
{
|
{
|
||||||
protected static $fixture_file = 'UserDefinedFormTest.yml';
|
protected static $fixture_file = 'userforms/tests/Model/UserDefinedFormTest.yml';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that a form will not generate empty pages
|
* Tests that a form will not generate empty pages
|
||||||
|
@ -6,6 +6,7 @@ use SilverStripe\Core\Config\Config;
|
|||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\Forms\CompositeField;
|
use SilverStripe\Forms\CompositeField;
|
||||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
||||||
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
||||||
use SilverStripe\Forms\LiteralField;
|
use SilverStripe\Forms\LiteralField;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField;
|
||||||
|
|
||||||
@ -17,7 +18,8 @@ class EditableLiteralFieldTest extends SapphireTest
|
|||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
HTMLEditorConfig::set_active('cms');
|
$cmsConfig = HTMLEditorConfig::get('cms');
|
||||||
|
HTMLEditorConfig::set_active($cmsConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,12 +32,12 @@ class EditableLiteralFieldTest extends SapphireTest
|
|||||||
$field = new EditableLiteralField();
|
$field = new EditableLiteralField();
|
||||||
|
|
||||||
// Test with sanitisation enabled
|
// Test with sanitisation enabled
|
||||||
Config::modify()->update('HtmlEditorField', 'sanitise_server_side', true);
|
Config::modify()->set(HTMLEditorField::class, 'sanitise_server_side', true);
|
||||||
$field->setContent($rawContent);
|
$field->setContent($rawContent);
|
||||||
$this->assertEquals($safeContent, $field->getContent());
|
$this->assertEquals($safeContent, $field->getContent());
|
||||||
|
|
||||||
// Test with sanitisation disabled
|
// Test with sanitisation disabled
|
||||||
Config::modify()->remove('HtmlEditorField', 'sanitise_server_side');
|
Config::modify()->remove(HTMLEditorField::class, 'sanitise_server_side');
|
||||||
$field->setContent($rawContent);
|
$field->setContent($rawContent);
|
||||||
$this->assertEquals($rawContent, $field->getContent());
|
$this->assertEquals($rawContent, $field->getContent());
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ SilverStripe\UserForms\Model\EditableCustomRule:
|
|||||||
Display: Show
|
Display: Show
|
||||||
ConditionOption: HasValue
|
ConditionOption: HasValue
|
||||||
FieldValue: NZ
|
FieldValue: NZ
|
||||||
ConditionField: =>EditableFormField.countryTextField
|
ConditionField: =>SilverStripe\UserForms\Model\EditableFormField.countryTextField
|
||||||
Parent: =>EditableFormField.irdNumberField
|
Parent: =>SilverStripe\UserForms\Model\EditableFormField.irdNumberField
|
||||||
rule-1:
|
rule-1:
|
||||||
Display: Hide
|
Display: Hide
|
||||||
ConditionOption: HasValue
|
ConditionOption: HasValue
|
||||||
|
@ -4,7 +4,7 @@ SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
|
|||||||
SilverStripe\UserForms\Model\EditableFormField\EditableNumericField:
|
SilverStripe\UserForms\Model\EditableFormField\EditableNumericField:
|
||||||
ageField:
|
ageField:
|
||||||
Name: Age
|
Name: Age
|
||||||
SilverStripe\UserForms\Model\EditableFormField\EmailRecipientCondition:
|
SilverStripe\UserForms\Model\Recipient\EmailRecipientCondition:
|
||||||
blankTest:
|
blankTest:
|
||||||
ConditionOption: IsBlank
|
ConditionOption: IsBlank
|
||||||
ConditionValue: null
|
ConditionValue: null
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\UserForms\Test\Model;
|
namespace SilverStripe\UserForms\Test\Model;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Dev\CSSContentParser;
|
use SilverStripe\Dev\CSSContentParser;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
||||||
@ -227,7 +228,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
$actions = $controller->Form()->getFormActions();
|
$actions = $controller->Form()->getFormActions();
|
||||||
|
|
||||||
$expected = new FieldList(new FormAction('process', 'Custom Button'));
|
$expected = new FieldList(new FormAction('process', 'Custom Button'));
|
||||||
$expected->push(new ResetFormAction("clearForm", "Clear"));
|
$expected->push(FormAction::create('clearForm', 'Clear')->setAttribute('type', 'reset'));
|
||||||
$expected->setForm($controller->Form());
|
$expected->setForm($controller->Form());
|
||||||
|
|
||||||
$this->assertEquals($actions, $expected);
|
$this->assertEquals($actions, $expected);
|
||||||
@ -237,8 +238,9 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
{
|
{
|
||||||
$form = $this->setupFormFrontend();
|
$form = $this->setupFormFrontend();
|
||||||
|
|
||||||
|
$this->logInWithPermission('ADMIN');
|
||||||
$form->Content = 'This is some content without a form nested between it';
|
$form->Content = 'This is some content without a form nested between it';
|
||||||
$form->doPublish();
|
$form->publishRecursive();
|
||||||
|
|
||||||
$controller = new UserDefinedFormController($form);
|
$controller = new UserDefinedFormController($form);
|
||||||
|
|
||||||
@ -272,7 +274,7 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
$form = $this->objFromFixture(UserDefinedForm::class, $fixtureName);
|
$form = $this->objFromFixture(UserDefinedForm::class, $fixtureName);
|
||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
|
|
||||||
$form->doPublish();
|
$form->publishRecursive();
|
||||||
|
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
$member->logOut();
|
$member->logOut();
|
||||||
|
@ -282,7 +282,7 @@ SilverStripe\UserForms\Model\UserDefinedForm:
|
|||||||
filtered-form-page:
|
filtered-form-page:
|
||||||
Title: 'Page with filtered recipients'
|
Title: 'Page with filtered recipients'
|
||||||
Fields: =>SilverStripe\UserForms\Model\EditableFormField\EditableFormStep.form5step1,=>SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField.checkbox-group, =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.your-name-field, =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.street-field, =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.city-field
|
Fields: =>SilverStripe\UserForms\Model\EditableFormField\EditableFormStep.form5step1,=>SilverStripe\UserForms\Model\EditableFormField\EditableCheckboxGroupField.checkbox-group, =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.your-name-field, =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.street-field, =>SilverStripe\UserForms\Model\EditableFormField\EditableTextField.city-field
|
||||||
EmailRecipients: =>EmailRecipient.unfiltered-recipient-1, =>EmailRecipient.filtered-recipient-1, =>EmailRecipient.filtered-recipient-2
|
EmailRecipients: =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.unfiltered-recipient-1, =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.filtered-recipient-1, =>SilverStripe\UserForms\Model\Recipient\EmailRecipient.filtered-recipient-2
|
||||||
|
|
||||||
empty-page:
|
empty-page:
|
||||||
Title: 'Page with empty step'
|
Title: 'Page with empty step'
|
||||||
|
Loading…
Reference in New Issue
Block a user