From ab402b117c9fc510e20a2f80ff2243f1fa5a43f3 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 15 Aug 2018 17:00:49 +1200 Subject: [PATCH 1/6] FIX Submitted form field values are no longer double escaped in the CMS --- code/Model/Submission/SubmittedFormField.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/code/Model/Submission/SubmittedFormField.php b/code/Model/Submission/SubmittedFormField.php index 7085ae9..1be0cd7 100755 --- a/code/Model/Submission/SubmittedFormField.php +++ b/code/Model/Submission/SubmittedFormField.php @@ -3,7 +3,9 @@ namespace SilverStripe\UserForms\Model\Submission; use SilverStripe\ORM\DataObject; -use SilverStripe\UserForms\Model\Submission\SubmittedForm; +use SilverStripe\ORM\FieldType\DBField; +use SilverStripe\Security\Member; +use SilverStripe\UserForms\Model\EditableFormField; /** * Data received from a UserDefinedForm submission @@ -27,10 +29,6 @@ class SubmittedFormField extends DataObject 'FormattedValue' => 'Value' ]; - private static $casting = [ - 'FormattedValue' => 'HTMLFragment' - ]; - private static $table_name = 'SubmittedFormField'; /** @@ -76,20 +74,20 @@ class SubmittedFormField extends DataObject /** * 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 + * so they will output as newlines in the reports. * - * @return string + * @return DBField */ public function getFormattedValue() { - return nl2br($this->dbObject('Value')->ATT()); + return $this->dbObject('Value'); } /** * Return the value of this submitted form field suitable for inclusion * into the CSV * - * @return Text + * @return DBField */ public function getExportValue() { From 6e3eea22bcb03bcfd3fdd7acd59de0a11c9bd839 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 3 Sep 2018 07:56:52 +0200 Subject: [PATCH 2/6] FIX Step navigation buttons are not translatable --- lang/en.yml | 2 ++ .../UserForms/Form/Includes/UserFormStepNav.ss | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lang/en.yml b/lang/en.yml index 3826e03..14db463 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -148,6 +148,8 @@ en: one: 'A Page Break' other: '{count} Page Breaks' SINGULARNAME: 'Page Break' + STEP_NEXT: Next + STEP_PREV: Prev STEP_TITLE: 'Page {page}' TITLE_FIRST: 'First Page' SilverStripe\UserForms\Model\EditableFormField\EditableLiteralField: diff --git a/templates/SilverStripe/UserForms/Form/Includes/UserFormStepNav.ss b/templates/SilverStripe/UserForms/Form/Includes/UserFormStepNav.ss index 61c1e7f..790245a 100644 --- a/templates/SilverStripe/UserForms/Form/Includes/UserFormStepNav.ss +++ b/templates/SilverStripe/UserForms/Form/Includes/UserFormStepNav.ss @@ -5,10 +5,14 @@ so the 'prev' and 'next' button are not used. These buttons are made visible via JavaScript. --%> <% if $Actions %> @@ -20,4 +24,4 @@ <% end_if %> - \ No newline at end of file + From f734c2f0330a8f1280737ffb31a1e2c61e51342f Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 3 Sep 2018 13:37:21 +0200 Subject: [PATCH 3/6] FIX Do not override core translation for 'field is required' --- code/Model/EditableFormField.php | 5 +++-- lang/en.yml | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/Model/EditableFormField.php b/code/Model/EditableFormField.php index 826b401..ddff655 100755 --- a/code/Model/EditableFormField.php +++ b/code/Model/EditableFormField.php @@ -27,6 +27,7 @@ use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; use SilverStripe\ORM\FieldType\DBField; +use SilverStripe\ORM\FieldType\DBVarchar; use SilverStripe\ORM\ValidationException; use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension; use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup; @@ -801,12 +802,12 @@ class EditableFormField extends DataObject * Return the error message for this field. Either uses the custom * one (if provided) or the default SilverStripe message * - * @return Varchar + * @return DBVarchar */ public function getErrorMessage() { $title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'"); - $standard = _t('SilverStripe\\Forms\\Form.FIELDISREQUIRED', '{name} is required.', ['name' => $title]); + $standard = _t(__CLASS__ . '.FIELDISREQUIRED', '{name} is required', ['name' => $title]); // only use CustomErrorMessage if it has a non empty value $errorMessage = (!empty($this->CustomErrorMessage)) ? $this->CustomErrorMessage : $standard; diff --git a/lang/en.yml b/lang/en.yml index 3826e03..6f5f1df 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -3,8 +3,6 @@ en: SELECTUPLOADFOLDER: 'Select upload folder' SilverStripe\CMS\Model\SiteTree: TABMAIN: Main - SilverStripe\Forms\Form: - FIELDISREQUIRED: '{name} is required.' SilverStripe\UserForms: ADDEMAILRECIPIENT: 'Add Email Recipient' CLEARBUTTON: Clear @@ -57,6 +55,7 @@ en: EXTRACLASS_SELECT: 'Select from the list of allowed styles' EXTRACLASS_TITLE: 'Extra Styling/Layout' EXTRACLASS_Title: 'Extra CSS classes' + FIELDISREQUIRED: '{name} is required' GROUP: Group INITIALVISIBILITY: 'Initial visibility' MERGEFIELDNAME: 'Merge field' From c88d6b1566659c0d5fac5ac408f05def0ecddee4 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 7 Sep 2018 10:45:11 +0200 Subject: [PATCH 4/6] FIX Recipient email content previews now when when userforms is used in a trait context --- code/Model/Recipient/EmailRecipient.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/code/Model/Recipient/EmailRecipient.php b/code/Model/Recipient/EmailRecipient.php index 4a3a546..0c686a4 100644 --- a/code/Model/Recipient/EmailRecipient.php +++ b/code/Model/Recipient/EmailRecipient.php @@ -234,12 +234,17 @@ class EmailRecipient extends DataObject ->getRequest() ->setSession(Controller::curr()->getRequest()->getSession()); + // If used in a regular page context, will have "/edit" on the end, if used in a trait context + // it won't. Strip that off in case. + $currentUrl = Controller::curr()->getRequest()->getURL(); + if (substr($currentUrl, -5) === '/edit') { + $currentUrl = substr($currentUrl, 0, strlen($currentUrl) - 5); + } + $previewUrl = Controller::join_links($currentUrl, 'preview'); + $preview = sprintf( '

%s

%s', - Controller::join_links( - $pageEditController->getEditForm()->FormAction(), - "field/EmailRecipients/item/{$this->ID}/preview" - ), + $previewUrl, _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL', 'Preview email'), _t( 'SilverStripe\\UserForms\\Model\\UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION', From 0ac33336bd9178002c558a01acec195a7cd30599 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 7 Sep 2018 12:50:34 +0200 Subject: [PATCH 5/6] FIX Do not remap polymorphic class names to UserDefinedForm if they are already an instance of it --- code/Extension/UpgradePolymorphicExtension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/code/Extension/UpgradePolymorphicExtension.php b/code/Extension/UpgradePolymorphicExtension.php index 6bf79d4..e8073a9 100644 --- a/code/Extension/UpgradePolymorphicExtension.php +++ b/code/Extension/UpgradePolymorphicExtension.php @@ -71,6 +71,11 @@ class UpgradePolymorphicExtension extends DataExtension continue; } + // Don't rewrite class values when an existing value is set and is an instance of UserDefinedForm + if ($relationshipObject instanceof UserDefinedForm) { + continue; + } + $entry->$fieldName = $this->defaultReplacement; try { $entry->write(); From 2b4451cdac85582f1bb82cd74162eb537031f424 Mon Sep 17 00:00:00 2001 From: Indy Griffiths <32345766+indygriffiths@users.noreply.github.com> Date: Fri, 21 Sep 2018 15:58:19 +1200 Subject: [PATCH 6/6] FIX DefaultToToday date format Fixes incorrectly using the minute (m) instead of the month (M) and switches to showing an 2018-09-21 format value --- code/Model/EditableFormField/EditableDateField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Model/EditableFormField/EditableDateField.php b/code/Model/EditableFormField/EditableDateField.php index d8cf23e..70d790c 100755 --- a/code/Model/EditableFormField/EditableDateField.php +++ b/code/Model/EditableFormField/EditableDateField.php @@ -55,7 +55,7 @@ class EditableDateField extends EditableFormField public function getFormField() { $defaultValue = $this->DefaultToToday - ? DBDatetime::now()->Format('Y-m-d') + ? DBDatetime::now()->Format('yyyy-MM-dd') : $this->Default; $field = FormField::create($this->Name, $this->Title ?: false, $defaultValue)