Skip to content

Commit

Permalink
DOC Update validate signature
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 16, 2024
1 parent b901a16 commit f5d58c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion en/02_Developer_Guides/00_Model/09_Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The return value of `validate()` is a [`ValidationResult`](api:SilverStripe\Core
namespace App\Model;

use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Validation\ValidationResult;

class MyObject extends DataObject
{
Expand All @@ -58,7 +59,7 @@ class MyObject extends DataObject
'Postcode' => 'Varchar',
];

public function validate()
public function validate(): ValidationResult
{
$result = parent::validate();

Expand Down
28 changes: 28 additions & 0 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ title: 6.0.0 (unreleased)
- [Bug fixes](#bug-fixes)
- [API changes](#api-changes)
- [Many renamed classes](#renamed-classes)
- [DataObject `validate()` signature change](#dataobject-validate)
- [GraphQL removed from the CMS](#graphql-removed)
- [`FormField` classes now use `FieldValidator` for validation](#formfield-validation)
- [Most extension hook methods are now protected](#hooks-protected)
Expand Down Expand Up @@ -928,6 +929,33 @@ The following classes have been changed when code was moved to the `silverstripe
|`SilverStripe\UserForms\Form\UserFormsRequiredFields`|[`SilverStripe\UserForms\Form\UserFormsRequiredFieldsValidator`](api:SilverStripe\UserForms\Form\UserFormsRequiredFieldsValidator)|
|`Symbiote\AdvancedWorkflow\Forms\AWRequiredFields`|[`Symbiote\AdvancedWorkflow\Forms\AWRequiredFieldsValidator`](api:Symbiote\AdvancedWorkflow\Forms\AWRequiredFieldsValidator)|

### DataObject `validate()` signature changed {#dataobject-validate}

The method signature of the `validate()` method on `DataObject` has changed as it is now strongly typed. It now explicitly returns a [`ValidationResult`](api:SilverStripe\Core\Validation\ValidationResult). Previously the method still returned a `ValidationResult`, though this was not defined in the method signature.

What this means is that you will now need to update the method sigature of any custom `validate()` methods you have in your `DataObject` subclasses to match the new signature.

```php
// app/src/Models/MyDataObject.php
namespace App\Models;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Validation\ValidationResult;
class MyDataObject extends DataObject
{
// ...
public function validate(): ValidationResult
{
$result = parent::validate();
if ($this->Title === 'Bad Title') {
$result->addError('Title cannot be "Bad Title"');
}
return $result;
}
}
```

### GraphQL removed from the CMS {#graphql-removed}

> [!NOTE]
Expand Down

0 comments on commit f5d58c1

Please sign in to comment.