From 7d25f7f535b808b7617f447317a037a4a44dc2c2 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 9 Dec 2024 12:11:33 +1300 Subject: [PATCH] API Deprecate renamed validators --- src/Forms/CompositeValidator.php | 8 +++++++- src/Forms/FieldsValidator.php | 14 ++++++++++++++ src/Forms/RequiredFields.php | 8 ++++++++ src/Forms/Validator.php | 8 ++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/Forms/CompositeValidator.php b/src/Forms/CompositeValidator.php index 2efbf5c6ea0..99fd7d4b72d 100644 --- a/src/Forms/CompositeValidator.php +++ b/src/Forms/CompositeValidator.php @@ -4,6 +4,7 @@ use InvalidArgumentException; use SilverStripe\ORM\ValidationResult; +use SilverStripe\Dev\Deprecation; /** * CompositeValidator can contain between 0 and many different types of Validators. Each Validator is itself still @@ -30,6 +31,7 @@ * { * $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent'])); * } + * @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\CompositeValidator */ class CompositeValidator extends Validator { @@ -45,8 +47,12 @@ class CompositeValidator extends Validator */ public function __construct(array $validators = []) { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be renamed to SilverStripe\\Forms\\Validation\\CompositeValidator', + Deprecation::SCOPE_CLASS + ); $this->validators = array_values($validators ?? []); - parent::__construct(); } diff --git a/src/Forms/FieldsValidator.php b/src/Forms/FieldsValidator.php index 0de96225fdf..c5de787c82b 100644 --- a/src/Forms/FieldsValidator.php +++ b/src/Forms/FieldsValidator.php @@ -2,11 +2,25 @@ namespace SilverStripe\Forms; +use SilverStripe\Dev\Deprecation; + /** * Validates the internal state of all fields in the form. + * + * @deprecated 5.4.0 Will be replaced with functionality inside SilverStripe\Forms\Form::validate() */ class FieldsValidator extends Validator { + public function __construct() + { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be replaced with functionality inside SilverStripe\Forms\Form::validate()', + Deprecation::SCOPE_CLASS + ); + parent::__construct(); + } + public function php($data): bool { $valid = true; diff --git a/src/Forms/RequiredFields.php b/src/Forms/RequiredFields.php index 3f0e055c0b7..64bde4139af 100644 --- a/src/Forms/RequiredFields.php +++ b/src/Forms/RequiredFields.php @@ -3,6 +3,7 @@ namespace SilverStripe\Forms; use SilverStripe\ORM\ArrayLib; +use SilverStripe\Dev\Deprecation; /** * Required Fields allows you to set which fields need to be present before @@ -11,6 +12,8 @@ * * Validation is performed on a field by field basis through * {@link FormField::validate}. + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\RequiredFieldsValidator */ class RequiredFields extends Validator { @@ -28,6 +31,11 @@ class RequiredFields extends Validator */ public function __construct() { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be renamed to SilverStripe\\Forms\\Validation\\RequiredFieldsValidator', + Deprecation::SCOPE_CLASS + ); $required = func_get_args(); if (isset($required[0]) && is_array($required[0])) { $required = $required[0]; diff --git a/src/Forms/Validator.php b/src/Forms/Validator.php index 60594e011d4..52219a51b00 100644 --- a/src/Forms/Validator.php +++ b/src/Forms/Validator.php @@ -6,11 +6,14 @@ use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; use SilverStripe\ORM\ValidationResult; +use SilverStripe\Dev\Deprecation; /** * This validation class handles all form and custom form validation through the use of Required * fields. It relies on javascript for client-side validation, and marking fields after server-side * validation. It acts as a visitor to individual form fields. + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\Validator */ abstract class Validator { @@ -20,6 +23,11 @@ abstract class Validator public function __construct() { + Deprecation::noticeWithNoReplacment( + '5.4.0', + 'Will be renamed to SilverStripe\\Forms\\Validation\\Validator', + Deprecation::SCOPE_CLASS + ); $this->resetResult(); }