Skip to content

Commit

Permalink
DOC Rename FormField method
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 11, 2025
1 parent 1ac73e3 commit 241fcba
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion en/02_Developer_Guides/03_Forms/00_Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions en/02_Developer_Guides/03_Forms/01_Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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');
}
});
Expand Down
2 changes: 1 addition & 1 deletion en/02_Developer_Guides/09_Security/05_Secure_Coding.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class MyForm extends Form
}
```

- `FormField->Value()`
- `FormField->getValue()`
- URLParams passed to a Controller-method

Example:
Expand Down
7 changes: 7 additions & 0 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 241fcba

Please sign in to comment.