From a81afd0853dfd84239c03dc589bede4526cc5f46 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 5 Dec 2024 17:30:05 +1300 Subject: [PATCH] API Rename validator classes --- code/Control/UserDefinedFormAdmin.php | 4 ++-- code/Extension/UserFormValidator.php | 4 ++-- code/Form/UserForm.php | 6 +++--- ...redFields.php => UserFormsRequiredFieldsValidator.php} | 8 ++++---- code/Model/EditableFormField/Validator.php | 4 ++-- ...sTest.php => UserFormsRequiredFieldsValidatorTest.php} | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) rename code/Form/{UserFormsRequiredFields.php => UserFormsRequiredFieldsValidator.php} (94%) rename tests/php/Form/{UserFormsRequiredFieldsTest.php => UserFormsRequiredFieldsValidatorTest.php} (94%) diff --git a/code/Control/UserDefinedFormAdmin.php b/code/Control/UserDefinedFormAdmin.php index e44e04302..3451d57d9 100644 --- a/code/Control/UserDefinedFormAdmin.php +++ b/code/Control/UserDefinedFormAdmin.php @@ -13,7 +13,7 @@ use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\OptionsetField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Forms\Schema\FormSchema; use SilverStripe\Forms\TextField; use SilverStripe\Forms\TreeDropdownField; @@ -192,7 +192,7 @@ private function buildConfirmFolderForm(string $suggestedFolderName = '', string ->setUseButtonTag(true) ); - return Form::create($this, 'ConfirmFolderForm', $fields, $actions, RequiredFields::create('ID')) + return Form::create($this, 'ConfirmFolderForm', $fields, $actions, RequiredFieldsValidator::create('ID')) ->setFormAction($this->Link('ConfirmFolderForm')) ->addExtraClass('form--no-dividers'); } diff --git a/code/Extension/UserFormValidator.php b/code/Extension/UserFormValidator.php index ba3271010..2e6c4091c 100644 --- a/code/Extension/UserFormValidator.php +++ b/code/Extension/UserFormValidator.php @@ -2,13 +2,13 @@ namespace SilverStripe\UserForms\Extension; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroup; use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd; use SilverStripe\UserForms\Model\EditableFormField; use SilverStripe\UserForms\Model\EditableFormField\EditableFormStep; -class UserFormValidator extends RequiredFields +class UserFormValidator extends RequiredFieldsValidator { public function php($data) { diff --git a/code/Form/UserForm.php b/code/Form/UserForm.php index a9b73e083..034f194bd 100644 --- a/code/Form/UserForm.php +++ b/code/Form/UserForm.php @@ -160,7 +160,7 @@ public function getFormActions() /** * Get the required form fields for this form. * - * @return RequiredFields + * @return RequiredFieldsValidator */ public function getRequiredFields() { @@ -172,7 +172,7 @@ public function getRequiredFields() ->filter('Required', true) ->column('Name'); $requiredNames = array_merge($requiredNames, $this->getEmailRecipientRequiredFields()); - $required = UserFormsRequiredFields::create($requiredNames); + $required = UserFormsRequiredFieldsValidator::create($requiredNames); $this->extend('updateRequiredFields', $required); $required->setForm($this); return $required; @@ -203,7 +203,7 @@ public function getButtonText() } /** - * Push fields into the RequiredFields array if they are used by any Email recipients. + * Push fields into the RequiredFieldsValidator array if they are used by any Email recipients. * Ignore if there is a backup i.e. the plain string field is set * * @return array required fields names diff --git a/code/Form/UserFormsRequiredFields.php b/code/Form/UserFormsRequiredFieldsValidator.php similarity index 94% rename from code/Form/UserFormsRequiredFields.php rename to code/Form/UserFormsRequiredFieldsValidator.php index d0ab86041..4764f793d 100644 --- a/code/Form/UserFormsRequiredFields.php +++ b/code/Form/UserFormsRequiredFieldsValidator.php @@ -6,13 +6,13 @@ use SilverStripe\Dev\Debug; use SilverStripe\Forms\FileField; use SilverStripe\Forms\FormField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\Core\ArrayLib; use SilverStripe\UserForms\Model\EditableFormField; use SilverStripe\Dev\Deprecation; /** - * An extension of RequiredFields which handles conditionally required fields. + * An extension of RequiredFieldsValidator which handles conditionally required fields. * * A conditionally required is a field that is required, but can be hidden by display rules. * When it is visible, (according to the submitted form data) it will be validated as required. @@ -23,7 +23,7 @@ * * @deprecated 5.4.0 Will be renamed to SilverStripe\UserForms\Form\UserFormsRequiredFieldsValidator */ -class UserFormsRequiredFields extends RequiredFields +class UserFormsRequiredFieldsValidator extends RequiredFieldsValidator { public function __construct() { @@ -108,7 +108,7 @@ private function getEditableFormFieldByName($name) /** * Check if the validation rules for the specified field are met by the provided data. * - * @note Logic replicated from php() method of parent class `SilverStripe\Forms\RequiredFields` + * @note Logic replicated from php() method of parent class `SilverStripe\Forms\Validation\RequiredFieldsValidator` * @param EditableFormField $field * @param array $data * @return bool diff --git a/code/Model/EditableFormField/Validator.php b/code/Model/EditableFormField/Validator.php index ddcf691d5..3fbaaa573 100644 --- a/code/Model/EditableFormField/Validator.php +++ b/code/Model/EditableFormField/Validator.php @@ -2,10 +2,10 @@ namespace SilverStripe\UserForms\Model\EditableFormField; -use SilverStripe\Forms\RequiredFields; +use SilverStripe\Forms\Validation\RequiredFieldsValidator; use SilverStripe\UserForms\Model\EditableFormField; -class Validator extends RequiredFields +class Validator extends RequiredFieldsValidator { /** * diff --git a/tests/php/Form/UserFormsRequiredFieldsTest.php b/tests/php/Form/UserFormsRequiredFieldsValidatorTest.php similarity index 94% rename from tests/php/Form/UserFormsRequiredFieldsTest.php rename to tests/php/Form/UserFormsRequiredFieldsValidatorTest.php index 9b45f96d2..0febbcc9d 100644 --- a/tests/php/Form/UserFormsRequiredFieldsTest.php +++ b/tests/php/Form/UserFormsRequiredFieldsValidatorTest.php @@ -5,12 +5,12 @@ use SilverStripe\CMS\Controllers\ModelAsController; use SilverStripe\Dev\Debug; use SilverStripe\Dev\SapphireTest; -use SilverStripe\UserForms\Form\UserFormsRequiredFields; +use SilverStripe\UserForms\Form\UserFormsRequiredFieldsValidator; use SilverStripe\UserForms\Model\UserDefinedForm; use SilverStripe\UserForms\Form\UserForm; use PHPUnit\Framework\Attributes\DataProvider; -class UserFormsRequiredFieldsTest extends SapphireTest +class UserFormsRequiredFieldsValidatorTest extends SapphireTest { protected static $fixture_file = '../UserFormsTest.yml'; @@ -21,13 +21,13 @@ private function getValidatorFromPage($page) return $form->getValidator(); } - public function testUsesUserFormsRequiredFieldsValidator() + public function testUsesUserFormsRequiredFormFieldsValidator() { $page = $this->objFromFixture(UserDefinedForm::class, 'required-custom-rules-form'); $this->assertEquals(3, $page->Fields()->count()); $validator = $this->getValidatorFromPage($page); $this->assertNotNull($validator); - $this->assertInstanceOf(UserFormsRequiredFields::class, $validator, 'Uses UserFormsRequiredFields validator'); + $this->assertInstanceOf(UserFormsRequiredFieldsValidator::class, $validator, 'Uses UserFormsRequiredFieldsValidator validator'); } public static function dataProviderValidationOfConditionalRequiredFields()