From 097e07f5800cd51a592f95d89e7e4c24ceca70f7 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 4 Nov 2024 15:48:10 +1300 Subject: [PATCH] API Use updated FormField::validate() signature --- src/Forms/WildcardDomainField.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Forms/WildcardDomainField.php b/src/Forms/WildcardDomainField.php index 90bf0587..50cefde1 100644 --- a/src/Forms/WildcardDomainField.php +++ b/src/Forms/WildcardDomainField.php @@ -2,6 +2,7 @@ namespace SilverStripe\Subsites\Forms; use SilverStripe\Forms\TextField; +use SilverStripe\Core\Validation\ValidationResult; /** * A text field that accepts only valid domain names, but allows the wildcard (*) character @@ -10,22 +11,21 @@ class WildcardDomainField extends TextField { /** * Validate this field as a valid hostname - * - * @param Validator $validator - * @return bool */ - public function validate($validator) + public function validate(): ValidationResult { - if ($this->checkHostname($this->Value())) { - return $this->extendValidationResult(true, $validator); - } - - $validator->validationError( - $this->getName(), - _t('DomainNameField.INVALID_DOMAIN', 'Invalid domain name'), - 'validation' - ); - return $this->extendValidationResult(false, $validator); + $result = ValidationResult::create(); + $this->beforeExtending('updateValidate', function () use ($result) { + if ($this->checkHostname($this->Value())) { + return; + } + $result->addFieldError( + $this->getName(), + _t('DomainNameField.INVALID_DOMAIN', 'Invalid domain name'), + 'validation' + ); + }); + return $result->combineAnd(parent::validate()); } /** @@ -36,7 +36,7 @@ public function validate($validator) */ public function checkHostname($hostname) { - return (bool)preg_match('/^([a-z0-9\*]+[\-\.\:])*([a-z0-9\*]+)$/', $hostname ?? ''); + return (bool) preg_match('/^([a-z0-9\*]+[\-\.\:])*([a-z0-9\*]+)$/', $hostname ?? ''); } public function Type()