From 241fcbaa34da17717d01f2334ee047a0476912d1 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 11 Feb 2025 17:53:07 +1300 Subject: [PATCH] DOC Rename FormField method --- en/02_Developer_Guides/03_Forms/00_Introduction.md | 2 +- en/02_Developer_Guides/03_Forms/01_Validation.md | 4 ++-- en/02_Developer_Guides/09_Security/05_Secure_Coding.md | 2 +- en/08_Changelogs/6.0.0.md | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/en/02_Developer_Guides/03_Forms/00_Introduction.md b/en/02_Developer_Guides/03_Forms/00_Introduction.md index 5270b8c0..f887801c 100644 --- a/en/02_Developer_Guides/03_Forms/00_Introduction.md +++ b/en/02_Developer_Guides/03_Forms/00_Introduction.md @@ -388,7 +388,7 @@ class MyFormPageController extends PageController echo $data['Email']; // You can also fetch the value from the field. - echo $form->Fields()->dataFieldByName('Email')->Value(); + echo $form->Fields()->dataFieldByName('Email')->getValue(); // Using the Form instance you can get / set status such as error messages. $form->sessionMessage('Successful!', 'good'); diff --git a/en/02_Developer_Guides/03_Forms/01_Validation.md b/en/02_Developer_Guides/03_Forms/01_Validation.md index a348a8e3..04d3c65d 100644 --- a/en/02_Developer_Guides/03_Forms/01_Validation.md +++ b/en/02_Developer_Guides/03_Forms/01_Validation.md @@ -90,7 +90,7 @@ class FormFieldValidationExtension extends Extension { protected function updateValidate(ValidationResult $result): void { - if (str_ends_with($this->owner->Value(), '@example.com')) { + if (str_ends_with($this->owner->getValue(), '@example.com')) { $result->addFieldError( $this->getOwner()->Name(), 'Please provide a valid email address which does not end with @example.com' @@ -118,7 +118,7 @@ class CustomNumberField extends NumericField public function validate(): ValidationResult { $this->beforeExtending('updateValidate', function (ValidationResult $result) { - if ((int) $this->Value() === 20) { + if ((int) $this->getValue() === 20) { $result->addFieldError($this->Name(), 'This value cannot be 20'); } }); diff --git a/en/02_Developer_Guides/09_Security/05_Secure_Coding.md b/en/02_Developer_Guides/09_Security/05_Secure_Coding.md index 3f03c57f..fbd4cb96 100644 --- a/en/02_Developer_Guides/09_Security/05_Secure_Coding.md +++ b/en/02_Developer_Guides/09_Security/05_Secure_Coding.md @@ -144,7 +144,7 @@ class MyForm extends Form } ``` -- `FormField->Value()` +- `FormField->getValue()` - URLParams passed to a Controller-method Example: diff --git a/en/08_Changelogs/6.0.0.md b/en/08_Changelogs/6.0.0.md index 994902db..e5480f56 100644 --- a/en/08_Changelogs/6.0.0.md +++ b/en/08_Changelogs/6.0.0.md @@ -37,6 +37,7 @@ title: 6.0.0 (unreleased) - [`FormField` classes now use `FieldValidator` for validation](#formfield-validation) - [Most extension hook methods are now protected](#hooks-protected) - [Changes to some extension hook names](#hooks-renamed) + - [`FormField::Value()` split into two methods](#formfield-value) - [Strict typing for `Factory` implementations](#factory-strict-typing) - [Elemental `TopPage` class names changed](#elemental-top-page) - [List interface changes](#list-interface-changes) @@ -1044,6 +1045,12 @@ The `updateCurrentRecordID` extension hook method is now invoked from [`LeftAndM If you have implemented any of those methods in an [`Extension`](api:SilverStripe\Core\Extension) subclass, you will need to rename them for them to continue working. +### `FormField::Value()` split into two methods {#formfield-value} + +`SilverStripe\Forms\FormField::Value()` has been split into to [`FormField::getValue()`](api:SilverStripe\Forms\FormField::getValue()) which usually returns an unmodified version of the value, and [`FormField::getFormattedValue()`](api:SilverStripe\Forms\FormField::getFormattedValue()) which is intended to be modified with things like localisation formatting and will be displayed to users. + +If you have overridden the `Value()` method in a subclass, you will need to update the method name to one of these, depending on the purpose of the custom functionality. If you use `$Value` in a template to get the value of a form field, you will need to update it to `$FormattedValue`. + ### Strict typing for `Factory` implementations {#factory-strict-typing} The [`Factory::create()`](api:SilverStripe\Core\Injector\Factory::create()) method now has strict typehinting. The first argument must be a string, and either `null` or an object must be returned.