mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
6 Commits
64e1882b50
...
f823ec42dc
Author | SHA1 | Date | |
---|---|---|---|
|
f823ec42dc | ||
|
b02ac10fc8 | ||
|
8a538f78ff | ||
|
55564814b9 | ||
|
829a28dc68 | ||
|
5c9c5519f3 |
@ -40,7 +40,18 @@ trait SearchFilterable
|
|||||||
$filterServiceName = "DataListFilter.{$secondArg}";
|
$filterServiceName = "DataListFilter.{$secondArg}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_array($value)) {
|
||||||
|
foreach ($value as $key => $val) {
|
||||||
|
if ($val === '' || $val === 'null') {
|
||||||
|
$value[] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($value === '' || $value === 'null') {
|
||||||
|
$value = ['', null];
|
||||||
|
}
|
||||||
|
}
|
||||||
// Build instance
|
// Build instance
|
||||||
return Injector::inst()->create($filterServiceName, $fieldName, $value, $modifiers);
|
return Injector::inst()->create($filterServiceName, $fieldName, $value, $modifiers);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ use SilverStripe\Core\Convert;
|
|||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Dev\TestMailer;
|
use SilverStripe\Dev\TestMailer;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
|
use SilverStripe\Forms\CompositeValidator;
|
||||||
use SilverStripe\Forms\ConfirmedPasswordField;
|
use SilverStripe\Forms\ConfirmedPasswordField;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -697,6 +698,20 @@ class Member extends DataObject
|
|||||||
return $validator;
|
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
|
* Temporarily act as the specified user, limited to a $callback, but
|
||||||
|
21
tests/php/Core/Validation/MemberValidatorTest.php
Normal file
21
tests/php/Core/Validation/MemberValidatorTest.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user