From 8d97a7a3efde87858a0aae00f1534809026eceb5 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 13 Nov 2024 13:48:14 +1300 Subject: [PATCH] API Disable ancestor FieldValidators --- src/StringTagField.php | 20 +++++++------------- src/TagField.php | 20 +++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/StringTagField.php b/src/StringTagField.php index b994b19..78d4442 100644 --- a/src/StringTagField.php +++ b/src/StringTagField.php @@ -7,13 +7,13 @@ use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; use SilverStripe\Forms\DropdownField; -use SilverStripe\Forms\Validator; use SilverStripe\Model\List\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectInterface; use SilverStripe\Model\List\SS_List; use SilverStripe\Model\ArrayData; use SilverStripe\View\Requirements; +use SilverStripe\Core\Validation\FieldValidation\OptionFieldValidator; /** * Provides a tagging interface, storing comma-delimited tags in a DataObject string field. @@ -26,6 +26,12 @@ */ class StringTagField extends DropdownField { + private static array $field_validators = [ + // Disable validation as StringTagField is a special case where labels can be the values + // rather than the keys always being the values - for instance when creating new tags + OptionFieldValidator::class => null, + ]; + /** * @var array */ @@ -356,18 +362,6 @@ protected function getTags($term) return array_slice(array_values($items ?? []), 0, $this->getLazyLoadItemLimit()); } - /** - * DropdownField assumes value will be a scalar so we must - * override validate. This only applies to Silverstripe 3.2+ - * - * @param Validator $validator - * @return bool - */ - public function validate($validator) - { - return $this->extendValidationResult(true, $validator); - } - /** * @return bool */ diff --git a/src/TagField.php b/src/TagField.php index 10fb9be..6553197 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -8,7 +8,6 @@ use SilverStripe\Control\HTTPResponse; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\MultiSelectField; -use SilverStripe\Forms\Validator; use SilverStripe\Model\List\ArrayList; use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataObject; @@ -17,6 +16,7 @@ use SilverStripe\ORM\Relation; use SilverStripe\Model\List\SS_List; use SilverStripe\Model\ArrayData; +use SilverStripe\Core\Validation\FieldValidation\MultiOptionFieldValidator; /** * Provides a tagging interface, storing links between tag DataObjects and a parent DataObject. @@ -26,6 +26,12 @@ */ class TagField extends MultiSelectField { + private static array $field_validators = [ + // Disable validation as TagField is a special case where labels can be the values + // rather than the keys always being the values - for instance when creating new tags + MultiOptionFieldValidator::class => null, + ]; + /** * @var array */ @@ -562,18 +568,6 @@ protected function getTags($term) return array_values($items ?? []); } - /** - * DropdownField assumes value will be a scalar so we must - * override validate. This only applies to Silverstripe 3.2+ - * - * @param Validator $validator - * @return bool - */ - public function validate($validator) - { - return $this->extendValidationResult(true, $validator); - } - /** * Converts the field to a readonly variant. *