Skip to content

Commit

Permalink
API Replace getCMSValidator with getCMSCompositeValidator (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 9, 2025
1 parent 50d9c6b commit 8e46c34
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
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

0 comments on commit 8e46c34

Please sign in to comment.