Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Rename validator classes #11486

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Forms/FieldsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\Forms;

use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\Validation\Validator;

/**
* Validates the internal state of all fields in the form.
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
4 changes: 3 additions & 1 deletion src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use SilverStripe\View\AttributesHTML;
use SilverStripe\View\SSViewer;
use SilverStripe\Model\ModelData;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\Validation\Validator;

/**
* Base class for all forms.
Expand Down Expand Up @@ -297,7 +299,7 @@ public function __construct(
$this->setName($name);

// Form validation
$this->validator = ($validator) ? $validator : new RequiredFields();
$this->validator = ($validator) ? $validator : new RequiredFieldsValidator();
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
$this->validator->setForm($this);

// Form error controls
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FieldsValidator;
use SilverStripe\Forms\Validator;
use SilverStripe\Forms\Validation\Validator;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Model\ModelData;
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
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Forms;
namespace SilverStripe\Forms\Validation;

use InvalidArgumentException;
use SilverStripe\Core\Validation\ValidationResult;
Expand All @@ -20,7 +20,7 @@
* {
* $compositeValidator = parent::getCMSCompositeValidator();
*
* $compositeValidator->addValidator(RequiredFields::create(['MyRequiredField']));
* $compositeValidator->addValidator(RequiredFieldsValidator::create(['MyRequiredField']));
*
* return $compositeValidator
* }
Expand All @@ -29,9 +29,8 @@
*
* protected function updateCMSCompositeValidator(CompositeValidator $compositeValidator): void
* {
* $compositeValidator->addValidator(RequiredFields::create(['AdditionalContent']));
* $compositeValidator->addValidator(RequiredFieldsValidator::create(['AdditionalContent']));
* }
* @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\CompositeValidator
*/
class CompositeValidator extends Validator
{
Expand All @@ -47,11 +46,6 @@ class CompositeValidator extends Validator
*/
public function __construct(array $validators = [])
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\\Forms\\Validation\\CompositeValidator',
Deprecation::SCOPE_CLASS
);
$this->validators = array_values($validators ?? []);
parent::__construct();
}
Expand Down Expand Up @@ -106,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 @@ -156,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 @@ -181,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
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace SilverStripe\Forms;
namespace SilverStripe\Forms\Validation;

use SilverStripe\Core\ArrayLib;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\HasOneRelationFieldInterface;
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\FormField;

/**
* Required Fields allows you to set which fields need to be present before
Expand All @@ -12,10 +14,8 @@
*
* Validation is performed on a field by field basis through
* {@link FormField::validate}.
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\RequiredFieldsValidator
*/
class RequiredFields extends Validator
class RequiredFieldsValidator extends Validator
{
/**
* Whether to globally allow whitespace only as a valid value for a required field
Expand All @@ -42,11 +42,6 @@ class RequiredFields extends Validator
*/
public function __construct()
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\\Forms\\Validation\\RequiredFieldsValidator',
Deprecation::SCOPE_CLASS
);
$required = func_get_args();
if (isset($required[0]) && is_array($required[0])) {
$required = $required[0];
Expand Down Expand Up @@ -232,7 +227,7 @@ public function removeRequiredField($field)
/**
* Add {@link RequiredField} objects together
*
* @param RequiredFields $requiredFields
* @param RequiredFieldsValidator $requiredFields
* @return $this
*/
public function appendRequiredFields($requiredFields)
Expand Down
12 changes: 2 additions & 10 deletions src/Forms/Validator.php → src/Forms/Validation/Validator.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php

namespace SilverStripe\Forms;
namespace SilverStripe\Forms\Validation;

use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Dev\Deprecation;

/**
* This validation class handles all form and custom form validation through the use of Required
* fields. It relies on javascript for client-side validation, and marking fields after server-side
* validation. It acts as a visitor to individual form fields.
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\Forms\Validation\Validator
*/
abstract class Validator
{
Expand All @@ -23,11 +20,6 @@ abstract class Validator

public function __construct()
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\\Forms\\Validation\\Validator',
Deprecation::SCOPE_CLASS
);
$this->resetResult();
}

Expand Down Expand Up @@ -179,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
2 changes: 1 addition & 1 deletion src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\FormScaffolder;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\Validation\CompositeValidator;
use SilverStripe\Forms\FieldsValidator;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
Expand Down
6 changes: 3 additions & 3 deletions src/Security/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use SilverStripe\Admin\SecurityAdmin;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\Validation\CompositeValidator;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
Expand All @@ -23,7 +23,7 @@
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\Validation\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/LogoutForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\Validator;
use SilverStripe\Forms\Validation\Validator;

/**
* Log out form to display to users who arrive at 'Security/logout' without a
Expand Down
4 changes: 2 additions & 2 deletions src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\TestMailer;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\Validation\CompositeValidator;
use SilverStripe\Forms\ConfirmedPasswordField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
Expand Down 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\Validation\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\Validation\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\Validation\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\Validation\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\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;

class CompositeFieldTest extends SapphireTest
Expand Down
Loading
Loading