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 Replace getCMSValidator with getCMSCompositeValidator #223

Merged
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
7 changes: 5 additions & 2 deletions code/BasicFieldsTestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\HTMLReadonlyField;
use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Forms\Validation\CompositeValidator;

class BasicFieldsTestPage extends TestPage
{
Expand Down Expand Up @@ -398,9 +399,11 @@ public function getCMSFields()
return $fields;
}

public function getCMSValidator()
public function getCMSCompositeValidator(): CompositeValidator
{
return new RequiredFieldsValidator('Required');
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(new RequiredFieldsValidator('Required'));
return $validator;
}

public function validate(): ValidationResult
Expand Down
9 changes: 5 additions & 4 deletions code/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
use SilverStripe\Forms\Validation\CompositeValidator;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;

/**
Expand Down Expand Up @@ -101,11 +102,11 @@ public function getCMSFields()
return $fields;
}

public function getCMSValidator()
public function getCMSCompositeValidator(): CompositeValidator
{
return new RequiredFieldsValidator(
['Name']
);
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(new RequiredFieldsValidator(['Name']));
return $validator;
}

public function DynamicProperty()
Expand Down
9 changes: 5 additions & 4 deletions code/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\Validation\CompositeValidator;
use SilverStripe\ORM\Connect\MySQLSchemaManager;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
Expand Down Expand Up @@ -142,11 +143,11 @@ public function requireDefaultRecords()
srand();
}

public function getCMSValidator()
public function getCMSCompositeValidator(): CompositeValidator
{
return new RequiredFieldsValidator(
['Name']
);
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(new RequiredFieldsValidator(['Name']));
return $validator;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions code/multitab-validation/MultiTabPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\TextField;
use SilverStripe\Core\Validation\ValidationResult;
use SilverStripe\Forms\Validation\CompositeValidator;

if (!class_exists(Page::class)) {
return;
Expand Down Expand Up @@ -50,14 +51,16 @@ public function getSettingsFields()
return $fields;
}

public function getCMSValidator()
public function getCMSCompositeValidator(): CompositeValidator
{
return new RequiredFieldsValidator([
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(new RequiredFieldsValidator([
'ThirdTabFirstField',
'FourthTabFirstField',
// This is only validated if you are actually on the settings tab when clicking save
'SettingsTabFirstField'
]);
]));
return $validator;
}

public function validate(): ValidationResult
Expand Down
9 changes: 5 additions & 4 deletions code/multitab-validation/SingleTabPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Page;
use SilverStripe\Forms\Validation\RequiredFieldsValidator;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\Validation\CompositeValidator;

if (!class_exists(Page::class)) {
return;
Expand All @@ -17,11 +18,11 @@ class SingleTabPage extends Page
{
private static $table_name = 'SingleTabPage';

public function getCMSValidator()
public function getCMSCompositeValidator(): CompositeValidator
{
return new RequiredFieldsValidator([
'Content'
]);
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(new RequiredFieldsValidator(['Content']));
return $validator;
}

public function getCMSFields()
Expand Down
Loading