From a3896eb39e1b9051a99311dbad06648e4e6c59db Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Thu, 25 Jun 2020 16:44:11 +1200 Subject: [PATCH 1/3] Test postgresql (#979) --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ee01652..5736b58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ dist: xenial services: - mysql + - postgresql env: global: From 6f04f9537d3db09fa5a90c85dc1b75f1223c8e9b Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Thu, 25 Jun 2020 17:04:20 +1200 Subject: [PATCH 2/3] Fix linting issue --- code/Task/RecoverUploadLocationsHelper.php | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/code/Task/RecoverUploadLocationsHelper.php b/code/Task/RecoverUploadLocationsHelper.php index 2b0e8a2..c0f261d 100644 --- a/code/Task/RecoverUploadLocationsHelper.php +++ b/code/Task/RecoverUploadLocationsHelper.php @@ -62,7 +62,7 @@ class RecoverUploadLocationsHelper /** * Cache of the EditableFileField versions - * + * * @var EditableFileField */ private $fieldFolderCache = array(); @@ -115,7 +115,7 @@ class RecoverUploadLocationsHelper /** * Process all the files and return the number - * + * * @return int Number of files processed */ protected function process() @@ -134,7 +134,7 @@ class RecoverUploadLocationsHelper $errorsCount = 0; // Loop over the files to process - foreach($this->chunk() as $uploadRecord) { + foreach ($this->chunk() as $uploadRecord) { ++$processedCount; $fileId = $uploadRecord['UploadedFileID']; @@ -171,10 +171,10 @@ class RecoverUploadLocationsHelper /** * Fetches the EditableFileField version from cache and returns its FolderID - * + * * @param int $fieldId EditableFileField.ID * @param int EditableFileField Version - * + * * @return int */ protected function getExpectedUploadFolderId($fieldId, $fieldVersion) @@ -196,11 +196,11 @@ class RecoverUploadLocationsHelper /** * Fetches a Folder by its ID, gracefully handling * deleted folders - * + * * @param int $id Folder.ID - * + * * @return Folder - * + * * @throws RuntimeException when folder could not be found */ protected function getFolder($id) @@ -231,10 +231,10 @@ class RecoverUploadLocationsHelper /** * Recover an uploaded file location - * + * * @param int $fileId File.ID * @param int $expectedFolderId ID of the folder where the file should have end up - * + * * @return int Number of files recovered */ protected function recover($fileId, $expectedFolderId) @@ -247,7 +247,8 @@ class RecoverUploadLocationsHelper if ($this->filesVersioned) { $draftVersion = Versioned::get_versionnumber_by_stage(File::class, Versioned::DRAFT, $fileId); - $liveVersion = Versioned::get_versionnumber_by_stage(File::class, Versioned::LIVE, $fileId);; + $liveVersion = Versioned::get_versionnumber_by_stage(File::class, Versioned::LIVE, $fileId); + ; if ($draftVersion && $draftVersion != $liveVersion) { $draft = Versioned::get_version(File::class, $fileId, $draftVersion); @@ -305,11 +306,11 @@ class RecoverUploadLocationsHelper * when manually moving them to another folder through CMS * * @see https://github.com/silverstripe/silverstripe-userforms/issues/944 - * + * * @param int $fileId File.ID * @param File $file The live version of the file * @param File|null $draft The draft version of the file - * + * * @return int Number of files recovered */ protected function checkResidual($fileId, File $file, File $draft = null) @@ -370,7 +371,7 @@ class RecoverUploadLocationsHelper * * @param File $file the file instance * @param int $expectedFolder The expected folder - * + * * @return int How many files have been recovered */ protected function recoverLiveOnly(File $file, Folder $expectedFolder) @@ -560,11 +561,11 @@ limit 100 /** * Returns DataList object containing every * uploaded file record - * + * * @return DataList */ private function getCountQuery() { return SubmittedFileField::get()->filter(['UploadedFileID:NOT' => 0]); } -} \ No newline at end of file +} From 0c09eec6f84ab541e0c0615313b39231a22b4bda Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Mon, 6 Jul 2020 08:41:59 +1200 Subject: [PATCH 3/3] DOC Add docs around creating custom fields. Fixed #928 (#932) * Add docs around creating custom fields * Update docs/en/creating-custom-fields.md Co-authored-by: Steve Boyd --- docs/en/creating-custom-fields.md | 43 +++++++++++++++++++++++++++++++ docs/en/index.md | 1 + 2 files changed, 44 insertions(+) create mode 100644 docs/en/creating-custom-fields.md diff --git a/docs/en/creating-custom-fields.md b/docs/en/creating-custom-fields.md new file mode 100644 index 0000000..18f19d7 --- /dev/null +++ b/docs/en/creating-custom-fields.md @@ -0,0 +1,43 @@ +# Creating custom fields + +To create and use your own custom fields, depending on what you want to accomplish, you may need to create two +new classes subclassed from the following: + +- `EditableFormField` - this Field represents what will be seen/used in the CMS userforms interface +- `FormField` - this Field represents what will be seen/used in the frontend user form when the above field has been +added + +## How (without the "why") + +You need to create your own subclass of `EditableFormField` (the field which will be used in the CMS). This class needs to +implement the method `getFormField()`, which will need to return an instantiated `FormField` to be used in the +frontend form. + +`EditableTextField` and `TextField` are two existing classes and probably the best example to look in to. + +## Why two different Fields? + +Consider the following example (`EditableTextField` and `TextField`). + +We have a field type that allows us to (optionally) set a minimum and maximum number of characters that can be input +into that particular field. + +As an author, when I create this field in the CMS, I want the ability to specify what those `min`/`max` settings are. +As a developer, I want to be able to add validation to make sure that these `min`/`max` values are valid (EG: `min` +is less than `max`). So, this class is going to need DB fields to store these min/max values, and it's going to need +some validation for when an author fills in those fields. + +As a frontend user, I want to fill in the field, and be notified when the value I have entered does not meet the +requirements. As a developer, I need to now compare the value entered by the user with the `min`/`max` values that the +author specified. + +So, we have two fields, with two different concerns. + +The subclass of `EditableFormField` is what you want to create to represent the field as it is used in the CMS. Its +validation should be based on what you require your **content authors** to enter. + +The subclass of `FormField` is what you want to create to represent the field as it is used on the frontend. Its +validation should be based on what you require your **frontend users** to enter. + +The subclass of `EditableFormField` is in charge of instantiating its `FormField` with any/all information the `FormField` +requires to perform its duty. diff --git a/docs/en/index.md b/docs/en/index.md index ef07f18..07b8b13 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -28,6 +28,7 @@ See the "require" section of [composer.json](https://github.com/silverstripe/sil * [Troubleshooting](troubleshooting.md) * [User Documentation](userguide/index.md) * [Compiling Front-End Files](compiling-front-end-files.md) + * [Creating Custom Fields](creating-custom-fields.md) * [Upgrading to SilverStripe 4](upgrading.md) ## Thanks