From e2fc0056fb5143d6a54edaf80114256073c9c579 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 7 Aug 2023 14:41:19 +1200 Subject: [PATCH 1/2] DOC Use correct class for keep_archived_assets config --- en/02_Developer_Guides/14_Files/04_File_Storage.md | 2 +- en/02_Developer_Guides/14_Files/05_File_Migration.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/en/02_Developer_Guides/14_Files/04_File_Storage.md b/en/02_Developer_Guides/14_Files/04_File_Storage.md index 8d2f738ea..200e83801 100644 --- a/en/02_Developer_Guides/14_Files/04_File_Storage.md +++ b/en/02_Developer_Guides/14_Files/04_File_Storage.md @@ -149,7 +149,7 @@ Changes are only tracked for file metadata (e.g. the `Title` attribute). You can opt-in to retaining the file content for replaced or removed files. ```yml -SilverStripe\Assets\Flysystem\FlysystemAssetStore: +SilverStripe\Assets\File: keep_archived_assets: true ``` diff --git a/en/02_Developer_Guides/14_Files/05_File_Migration.md b/en/02_Developer_Guides/14_Files/05_File_Migration.md index 57da2bb05..19e092b77 100644 --- a/en/02_Developer_Guides/14_Files/05_File_Migration.md +++ b/en/02_Developer_Guides/14_Files/05_File_Migration.md @@ -152,7 +152,7 @@ in order to avoid bloat. If you need to retain file contents (e.g. for auditing you can opt-in to this behaviour: ```yaml -SilverStripe\Assets\Flysystem\FlysystemAssetStore: +SilverStripe\Assets\File: keep_archived_assets: true ``` From ef31438ef571564554ad9a64042bfdaecab8d06b Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:27:03 +1200 Subject: [PATCH 2/2] DOC Document FieldsValidator (#319) --- .../03_Forms/00_Introduction.md | 7 +++++-- .../03_Forms/01_Validation.md | 20 ++++++++++++++++--- .../How_Tos/05_Simple_Contact_Form.md | 2 +- .../11_Integration/00_CSV_Import.md | 4 +--- .../Import_CSV_through_a_Controller.md | 4 ++-- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/en/02_Developer_Guides/03_Forms/00_Introduction.md b/en/02_Developer_Guides/03_Forms/00_Introduction.md index df21cd9a2..84281be78 100644 --- a/en/02_Developer_Guides/03_Forms/00_Introduction.md +++ b/en/02_Developer_Guides/03_Forms/00_Introduction.md @@ -27,7 +27,7 @@ $form = new Form( $name, // name of the method that returns this form on the controller FieldList $fields, // list of FormField instances FieldList $actions, // list of FormAction instances - $required // optional use of RequiredFields object + $validator // optional use of Validator object ); ``` @@ -343,7 +343,10 @@ validating its' own data value. For more information, see the [Form Validation](validation) documentation. ```php -$validator = new SilverStripe\Forms\RequiredFields([ +use SilverStripe\Forms\Form; +use SilverStripe\Forms\RequiredFields; + +$validator = new RequiredFields([ 'Name', 'Email' ]); diff --git a/en/02_Developer_Guides/03_Forms/01_Validation.md b/en/02_Developer_Guides/03_Forms/01_Validation.md index 4abcd0f9d..41696af2a 100644 --- a/en/02_Developer_Guides/03_Forms/01_Validation.md +++ b/en/02_Developer_Guides/03_Forms/01_Validation.md @@ -6,8 +6,8 @@ icon: check-square # Form Validation -Silverstripe CMS provides server-side form validation out of the box through the [Validator](api:SilverStripe\Forms\Validator) class and its' child class -[RequiredFields](api:SilverStripe\Forms\RequiredFields). A single `Validator` instance is set on each `Form`. Validators are implemented as an argument to +Silverstripe CMS provides server-side form validation out of the box through the [Validator](api:SilverStripe\Forms\Validator) class and its' child classes +(see [available validators](#available-validators) below). A single `Validator` instance is set on each `Form`. Validators are implemented as an argument to the [Form](api:SilverStripe\Forms\Form) constructor or through the function `setValidator`. ```php @@ -181,6 +181,20 @@ class Page_Controller extends ContentController } ``` +## Available validators + +The Silverstripe framework comes with the following built-in validators: + +- [`CompositeValidator`](api:SilverStripe\Forms\CompositeValidator) + A container for additional validators. You can implement discrete validation logic in multiple `Validator` subclasses and apply them _all_ to a + given form by putting them inside a `CompositeValidator`. The `CompositeValidator` doesn't have perform any validation by itself. +- [`FieldsValidator`](api:SilverStripe\Forms\FieldsValidator) + Simply calls [`validate()`](api:SilverStripe\Forms\FormField::validate()) on all data fields in the form, to ensure fields have valid values. +- [`RequiredFields`](api:SilverStripe\Forms\RequiredFields) + Validates that fields you declare as "required" have a value. + +There are additional validators available in community modules, and you can implement your own validators by subclassing the abstract `Validator` class. + ## Exempt validation actions In some cases you might need to disable validation for specific actions. E.g. actions which discard submitted @@ -274,7 +288,7 @@ class MyController extends Controller ### Validation in the CMS In the CMS, we're not creating the forms for editing CMS records. The `Form` instance is generated for us so we cannot -call `setValidator` easily. However, a `DataObject` can provide its' own `Validator` instance/s through the +call `setValidator` easily. However, a `DataObject` can provide its own `Validator` instance/s through the `getCMSCompositeValidator()` method. The CMS interfaces such as [LeftAndMain](api:SilverStripe\Admin\LeftAndMain), [ModelAdmin](api:SilverStripe\Admin\ModelAdmin) and [GridField](api:SilverStripe\Forms\GridField\GridField) will respect the provided `Validator`/s and handle displaying error and success responses to the user. diff --git a/en/02_Developer_Guides/03_Forms/How_Tos/05_Simple_Contact_Form.md b/en/02_Developer_Guides/03_Forms/How_Tos/05_Simple_Contact_Form.md index 4d586c77e..161bd4f45 100644 --- a/en/02_Developer_Guides/03_Forms/How_Tos/05_Simple_Contact_Form.md +++ b/en/02_Developer_Guides/03_Forms/How_Tos/05_Simple_Contact_Form.md @@ -139,7 +139,7 @@ This data is used to create an email, which you then send to the address you cho The final thing we do is return a 'thank you for your feedback' message to the user. To do this we override some of the methods called in the template by returning an array. We return the HTML content we want rendered instead of the usual CMS-entered content, and we return false for Form, as we don't want the form to render. -##How to add form validation +## How to add form validation All forms have some basic validation built in – email fields will only let the user enter email addresses, number fields will only accept numbers, and so on. Sometimes you need more complicated validation, so you can define your own validation by extending the Validator class. diff --git a/en/02_Developer_Guides/11_Integration/00_CSV_Import.md b/en/02_Developer_Guides/11_Integration/00_CSV_Import.md index 8f5a1bd99..21401d8d8 100644 --- a/en/02_Developer_Guides/11_Integration/00_CSV_Import.md +++ b/en/02_Developer_Guides/11_Integration/00_CSV_Import.md @@ -88,7 +88,6 @@ use SilverStripe\Forms\Form; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FileField; use SilverStripe\Forms\FormAction; -use SilverStripe\Forms\RequiredFields; use SilverStripe\Dev\CsvBulkLoader; use SilverStripe\Control\Controller; @@ -114,8 +113,7 @@ class MyController extends Controller ), new FieldList( new FormAction('doUpload', 'Upload') - ), - new RequiredFields() + ) ); return $form; } diff --git a/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md b/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md index 10b5a355b..1400d5f69 100644 --- a/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md +++ b/en/02_Developer_Guides/11_Integration/How_Tos/Import_CSV_through_a_Controller.md @@ -16,7 +16,7 @@ use SilverStripe\Forms\Form; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FileField; use SilverStripe\Forms\FormAction; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\FieldsValidator; use SilverStripe\Dev\CsvBulkLoader; use SilverStripe\Control\Controller; @@ -45,7 +45,7 @@ class MyController extends Controller new FieldList( new FormAction('doUpload', 'Upload') ), - new RequiredFields() + new FieldsValidator() ); return $form; }