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 #1353

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
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\Validation\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\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)
{
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,31 +6,22 @@
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.
* When it is hidden, it will skip required validation.
*
* Required fields will be validated as usual.
* Conditionally required fields will be validated IF the display rules are satisfied in the submitted dataset.
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\UserForms\Form\UserFormsRequiredFieldsValidator
*/
class UserFormsRequiredFields extends RequiredFields
class UserFormsRequiredFieldsValidator extends RequiredFieldsValidator
{
public function __construct()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed to SilverStripe\\UserForms\\Form\\UserFormsRequiredFieldsValidator', Deprecation::SCOPE_CLASS);
parent::__construct(...func_get_args());
}

/**
* Allows validation of fields via specification of a php function for
* validation which is executed after the form is submitted.
Expand Down Expand Up @@ -108,7 +99,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
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\Validation\RequiredFieldsValidator;
use SilverStripe\UserForms\Model\EditableFormField;

class Validator extends RequiredFields
class Validator extends RequiredFieldsValidator
{
/**
*
Expand Down
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
Loading