Compare commits

...

6 Commits

Author SHA1 Message Date
Sunny Side Up
317cf5cc0c
Merge 4a6a3d19af62708450dfcb8944d6ea72f2e1b4f2 into b02ac10fc8495e429d017664ee8ed5efba38357f 2024-09-30 05:30:34 +13:00
github-actions
b02ac10fc8 Merge branch '5.3' into 5 2024-09-29 08:43:17 +00:00
Guy Sartorelli
8a538f78ff
Merge pull request #11395 from silverstripe-terraformers/bugfix/member-validator
FIX: Member form validator fix.
2024-09-27 14:51:23 +12:00
Mojmir Fendek
55564814b9 Add a test. 2024-09-27 14:44:29 +12:00
Mojmir Fendek
829a28dc68 FIX: Member form validator fix. 2024-09-23 08:59:35 +12:00
Sunny Side Up
4a6a3d19af
MINOR: adding SpelledOut method in DBInt 2023-12-18 16:28:44 +13:00
3 changed files with 43 additions and 1 deletions

View File

@ -64,7 +64,13 @@ class DBInt extends DBField
{
return sprintf('%d', $this->value);
}
public function SpelledOut()
{
$v = $this->prepValueForDB($this->value);
return (new NumberFormatter(i18n::get_locale(), NumberFormatter::SPELLOUT))->format($v);
}
public function scaffoldFormField($title = null, $params = null)
{
return NumericField::create($this->name, $title);

View File

@ -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;
@ -697,6 +698,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

View File

@ -0,0 +1,21 @@
<?php
namespace SilverStripe\Core\Tests\Validation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Security\Member;
use SilverStripe\Security\Member_Validator;
class MemberValidatorTest extends SapphireTest
{
protected $usesDatabase = false;
public function testMemberValidator(): void
{
$member = new Member();
$compositeValidator = $member->getCMSCompositeValidator();
$memberValidators = $compositeValidator->getValidatorsByType(Member_Validator::class);
$this->assertCount(1, $memberValidators, 'We expect exactly one member validator');
}
}