Skip to content

Commit

Permalink
API Rename validator classes
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 3, 2024
1 parent 4161aa4 commit 6b1b216
Show file tree
Hide file tree
Showing 44 changed files with 106 additions and 106 deletions.
10 changes: 5 additions & 5 deletions src/Forms/CompositeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* {
* $compositeValidator = parent::getCMSCompositeValidator();
*
* $compositeValidator->addValidator(RequiredFields::create(['MyRequiredField']));
* $compositeValidator->addValidator(RequiredFieldsValidator::create(['MyRequiredField']));
*
* return $compositeValidator
* }
Expand All @@ -28,7 +28,7 @@
*
* protected function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
* {
* $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent']));
* $compositeValidator->addValidator(RequiredFieldsValidator::create(['AdditionalContent']));
* }
*/
class CompositeValidator extends Validator
Expand Down Expand Up @@ -100,7 +100,7 @@ public function validate()
}

/**
* Note: The existing implementations for the php() method (@see RequiredFields) does not check whether the
* Note: The existing implementations for the php() method (@see RequiredFieldsValidator) does not check whether the
* Validator is enabled or not, and it also does not reset the validation result - so, neither does this.
*
* @param array $data
Expand Down Expand Up @@ -150,7 +150,7 @@ public function getValidators(): array
}

/**
* Return all Validators that match a certain class name. EG: RequiredFields::class
* Return all Validators that match a certain class name. EG: RequiredFieldsValidator::class
*
* The keys for the return array match the keys in the unfiltered array. You cannot assume the keys will be
* sequential or that the first key will be ZERO.
Expand All @@ -175,7 +175,7 @@ public function getValidatorsByType(string $className): array
}

/**
* Remove all Validators that match a certain class name. EG: RequiredFields::class
* Remove all Validators that match a certain class name. EG: RequiredFieldsValidator::class
*
* @param string $className
* @return CompositeValidator
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/FileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* $actions = new FieldList(
* new FormAction('doUpload', 'Upload file')
* );
* $validator = new RequiredFields(['MyName', 'MyFile']);
* $validator = new RequiredFieldsValidator(['MyName', 'MyFile']);
*
* return new Form($this, 'Form', $fields, $actions, $validator);
* }
Expand Down
6 changes: 3 additions & 3 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* Each form needs some form of {@link Validator} to trigger the {@link FormField->validate()} methods for each field.
* You can't disable validator for security reasons, because crucial behaviour like extension checks for file uploads
* depend on it.
* The default validator is an instance of {@link RequiredFields}.
* The default validator is an instance of {@link RequiredFieldsValidator}.
* If you want to enforce serverside-validation to be ignored for a specific {@link FormField},
* you need to subclass it.
*
Expand Down Expand Up @@ -274,7 +274,7 @@ class Form extends ModelData implements HasRequestHandler
* @param FieldList $fields All of the fields in the form - a {@link FieldList} of {@link FormField} objects.
* @param FieldList $actions All of the action buttons in the form - a {@link FieldLis} of
* {@link FormAction} objects
* @param Validator|null $validator Override the default validator instance (Default: {@link RequiredFields})
* @param Validator|null $validator Override the default validator instance (Default: {@link RequiredFieldsValidator})
*/
public function __construct(
RequestHandler $controller = null,
Expand All @@ -297,7 +297,7 @@ public function __construct(
$this->setName($name);

// Form validation
$this->validator = ($validator) ? $validator : new RequiredFields();
$this->validator = ($validator) ? $validator : new RequiredFieldsValidator();
$this->validator->setForm($this);

// Form error controls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Validates the internal state of all fields in the form.
*/
class FieldsValidator extends Validator
class FormFieldsValidator extends Validator
{
public function php($data): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/GridField/GridFieldDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FieldsValidator;
use SilverStripe\Forms\FormFieldsValidator;
use SilverStripe\Forms\Validator;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -148,7 +148,7 @@ public function handleItem($gridField, $request)
if ($record->hasMethod('getCMSCompositeValidator')) {
$validator = $record->getCMSCompositeValidator();
} else {
$validator = FieldsValidator::create();
$validator = FormFieldsValidator::create();
}
$this->setValidator($validator);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/HasOneRelationFieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* Added to form fields whose values are the ID of a has_one relation
* This is used in RequiredFields validation to check if the value is set
* This is used in RequiredFieldsValidator validation to check if the value is set
*/
interface HasOneRelationFieldInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Validation is performed on a field by field basis through
* {@link FormField::validate}.
*/
class RequiredFields extends Validator
class RequiredFieldsValidator extends Validator
{

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ public function removeRequiredField($field)
/**
* Add {@link RequiredField} objects together
*
* @param RequiredFields $requiredFields
* @param RequiredFieldsValidator $requiredFields
* @return $this
*/
public function appendRequiredFields($requiredFields)
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function removeValidation()
/**
* When Validators are set on the form, it can affect whether or not the form cannot be cached.
*
* @see RequiredFields for an example of when you might be able to cache your form.
* @see RequiredFieldsValidator for an example of when you might be able to cache your form.
*
* @return bool
*/
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\FormScaffolder;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\FieldsValidator;
use SilverStripe\Forms\FormFieldsValidator;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\Forms\HiddenField;
Expand Down Expand Up @@ -2686,7 +2686,7 @@ public function getCMSActions()
*/
public function getCMSCompositeValidator(): CompositeValidator
{
$compositeValidator = CompositeValidator::create([FieldsValidator::create()]);
$compositeValidator = CompositeValidator::create([FormFieldsValidator::create()]);

// Support for the old method during the deprecation period
if ($this->hasMethod('getCMSValidator')) {
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextareaField;
Expand Down Expand Up @@ -559,7 +559,7 @@ public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();

$validator->addValidator(RequiredFields::create([
$validator->addValidator(RequiredFieldsValidator::create([
'Title'
]));

Expand Down
2 changes: 1 addition & 1 deletion src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ public function getMemberPasswordField()


/**
* Returns the {@link RequiredFields} instance for the Member object. This
* Returns the {@link RequiredFieldsValidator} instance for the Member object. This
* Validator is used when saving a {@link CMSProfileController} or added to
* any form responsible for saving a users data.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Security/MemberAuthenticator/MemberLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\PasswordField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;
use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Security\LoginForm as BaseLoginForm;
Expand Down Expand Up @@ -111,7 +111,7 @@ public function __construct(
if (isset($logoutAction)) {
$this->setFormAction($logoutAction);
}
$this->setValidator(RequiredFields::create(static::config()->get('required_fields')));
$this->setValidator(RequiredFieldsValidator::create(static::config()->get('required_fields')));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Member_Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\Security;

use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;

/**
* Member Validator
Expand All @@ -22,7 +22,7 @@
* - Surname
* </code>
*/
class Member_Validator extends RequiredFields
class Member_Validator extends RequiredFieldsValidator
{
/**
* Fields that are required by this validator
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/CheckboxFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\ORM\DB;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;

class CheckboxFieldTest extends SapphireTest
{
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testNoAriaRequired()
"form",
new FieldList($field),
new FieldList(),
new RequiredFields(["RequiredField"])
new RequiredFieldsValidator(["RequiredField"])
);
$this->assertTrue($field->Required());

Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/CheckboxSetFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Model\ArrayData;

class CheckboxSetFieldTest extends SapphireTest
Expand Down Expand Up @@ -355,7 +355,7 @@ public function testNoAriaRequired()
"form",
new FieldList($field),
new FieldList(),
new RequiredFields(["RequiredField"])
new RequiredFieldsValidator(["RequiredField"])
);
$this->assertTrue($field->Required());

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/CompositeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;

class CompositeFieldTest extends SapphireTest
Expand Down
30 changes: 15 additions & 15 deletions tests/php/Forms/CompositeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\Tests\ValidatorTest\TestValidator;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CompositeValidator;
Expand Down Expand Up @@ -40,8 +40,8 @@ protected function getForm(array $fieldNames = []): Form
public function testAddValidator(): void
{
$compositeValidator = new CompositeValidator();
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFieldsValidator());
$compositeValidator->addValidator(new RequiredFieldsValidator());

$this->assertCount(2, $compositeValidator->getValidators());
}
Expand Down Expand Up @@ -76,38 +76,38 @@ public function testSetForm(): void
public function testGetValidatorsByType(): void
{
$compositeValidator = new CompositeValidator();
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFieldsValidator());
$compositeValidator->addValidator(new TestValidator());
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFieldsValidator());
$compositeValidator->addValidator(new TestValidator());

$this->assertCount(4, $compositeValidator->getValidators());
$this->assertCount(2, $compositeValidator->getValidatorsByType(RequiredFields::class));
$this->assertCount(2, $compositeValidator->getValidatorsByType(RequiredFieldsValidator::class));
}

public function testRemoveValidatorsByType(): void
{
$compositeValidator = new CompositeValidator();
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFieldsValidator());
$compositeValidator->addValidator(new TestValidator());
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFieldsValidator());
$compositeValidator->addValidator(new TestValidator());

$this->assertCount(4, $compositeValidator->getValidators());

$compositeValidator->removeValidatorsByType(RequiredFields::class);
$compositeValidator->removeValidatorsByType(RequiredFieldsValidator::class);
$this->assertCount(2, $compositeValidator->getValidators());
}

public function testCanBeCached(): void
{
$compositeValidator = new CompositeValidator();
$compositeValidator->addValidator(new RequiredFields());
$compositeValidator->addValidator(new RequiredFieldsValidator());

$this->assertTrue($compositeValidator->canBeCached());

$compositeValidator = new CompositeValidator();
$compositeValidator->addValidator(new RequiredFields(['Foor']));
$compositeValidator->addValidator(new RequiredFieldsValidator(['Foor']));

$this->assertFalse($compositeValidator->canBeCached());
}
Expand All @@ -121,12 +121,12 @@ public function testFieldIsRequired(): void
'Content',
];

$requiredFieldsFirst = new RequiredFields(
$requiredFieldsFirst = new RequiredFieldsValidator(
[
$fieldNames[0],
]
);
$requiredFieldsSecond = new RequiredFields(
$requiredFieldsSecond = new RequiredFieldsValidator(
[
$fieldNames[1],
]
Expand All @@ -147,8 +147,8 @@ public function testValidate(): void
{
$compositeValidator = new CompositeValidator();
// Add two separate validators, each with one required field
$compositeValidator->addValidator(new RequiredFields(['Foo']));
$compositeValidator->addValidator(new RequiredFields(['Bar']));
$compositeValidator->addValidator(new RequiredFieldsValidator(['Foo']));
$compositeValidator->addValidator(new RequiredFieldsValidator(['Bar']));

// Setup a form with the fields/data we're testing (a form is a dependency for validation right now)
// We'll add three empty fields, but only two of them should be required
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Forms/ConfirmedPasswordFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Security\Member;
use SilverStripe\View\SSViewer;
use Closure;
Expand Down Expand Up @@ -466,7 +466,7 @@ public function testChildFieldsAreRequired(bool $canBeEmpty, bool $required, boo
$requiredFields[] = 'Test[_Password]';
$requiredFields[] = 'Test[_ConfirmPassword]';
}
$form->setValidator(new RequiredFields($requiredFields));
$form->setValidator(new RequiredFieldsValidator($requiredFields));

$rendered = $field->Field();
$fieldOneRegex = '<input\s+type="password"\s+name="Test\[_Password\]"\s[^>]*?required="required"\s+aria-required="true"\s[^>]*\/>';
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/CurrencyFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\CurrencyField;
use SilverStripe\Forms\CurrencyField_Readonly;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\ORM\FieldType\DBCurrency;

class CurrencyFieldTest extends SapphireTest
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Forms/DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\DateField_Disabled;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\FieldType\DBDate;
use SilverStripe\ORM\FieldType\DBDatetime;
Expand Down
Loading

0 comments on commit 6b1b216

Please sign in to comment.