From 829a28dc68906ea9311fbeacec0edaa764edf0a8 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Fri, 20 Sep 2024 14:04:36 +1200 Subject: [PATCH 1/2] FIX: Member form validator fix. --- src/Security/Member.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Security/Member.php b/src/Security/Member.php index 2003e8f05..6d9889989 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -15,6 +15,7 @@ use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\TestMailer; use SilverStripe\Forms\CheckboxField; +use SilverStripe\Forms\CompositeValidator; use SilverStripe\Forms\ConfirmedPasswordField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; @@ -696,6 +697,20 @@ class Member extends DataObject return $validator; } + public function getCMSCompositeValidator(): CompositeValidator + { + // Add the member validator before extension point, so it's much easier to customise this + // via an extension + $this->beforeExtending( + 'updateCMSCompositeValidator', + function (CompositeValidator $compositeValidator): void { + $memberValidator = $this->getValidator(); + $compositeValidator->addValidator($memberValidator); + } + ); + + return parent::getCMSCompositeValidator(); + } /** * Temporarily act as the specified user, limited to a $callback, but From 55564814b90c7ea7b99f264eeef5dae3c1f26341 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Fri, 27 Sep 2024 14:44:29 +1200 Subject: [PATCH 2/2] Add a test. --- .../Core/Validation/MemberValidatorTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/php/Core/Validation/MemberValidatorTest.php diff --git a/tests/php/Core/Validation/MemberValidatorTest.php b/tests/php/Core/Validation/MemberValidatorTest.php new file mode 100644 index 000000000..f5e345061 --- /dev/null +++ b/tests/php/Core/Validation/MemberValidatorTest.php @@ -0,0 +1,21 @@ +getCMSCompositeValidator(); + + $memberValidators = $compositeValidator->getValidatorsByType(Member_Validator::class); + $this->assertCount(1, $memberValidators, 'We expect exactly one member validator'); + } +}