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 2, 2024
1 parent 0020f7d commit 622c564
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions code/Control/UserDefinedFormAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Forms\Schema\FormSchema;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TreeDropdownField;
Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions code/Extension/UserFormValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace SilverStripe\UserForms\Extension;

use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\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)
{
Expand Down
6 changes: 3 additions & 3 deletions code/Form/UserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function getFormActions()
/**
* Get the required form fields for this form.
*
* @return RequiredFields
* @return RequiredFieldsValidator
*/
public function getRequiredFields()
{
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use SilverStripe\Dev\Debug;
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\Core\ArrayLib;
use SilverStripe\UserForms\Model\EditableFormField;

/**
* 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.
Expand All @@ -20,7 +20,7 @@
* Required fields will be validated as usual.
* Conditionally required fields will be validated IF the display rules are satisfied in the submitted dataset.
*/
class UserFormsRequiredFields extends RequiredFields
class UserFormsRequiredFieldsValidator extends RequiredFieldsValidator
{
/**
* Allows validation of fields via specification of a php function for
Expand Down
4 changes: 2 additions & 2 deletions code/Model/EditableFormField/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace SilverStripe\UserForms\Model\EditableFormField;

use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\RequiredFieldsValidator;
use SilverStripe\UserForms\Model\EditableFormField;

class Validator extends RequiredFields
class Validator extends RequiredFieldsValidator
{
/**
*
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Form/UserFormsRequiredFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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()
Expand Down

0 comments on commit 622c564

Please sign in to comment.