-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4355b0
commit 5bc4ed8
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace SilverStripe\FrameworkTest\Elemental\Extension; | ||
|
||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\ORM\ValidationResult; | ||
use SilverStripe\Forms\CompositeValidator; | ||
use SilverStripe\Forms\NumericField; | ||
use SilverStripe\Forms\RequiredFields; | ||
use SilverStripe\Forms\TextField; | ||
|
||
/** | ||
* @extends Extension<ElementContent> | ||
*/ | ||
class ElementContentExtension extends Extension | ||
{ | ||
private static $db = [ | ||
'MyField' => 'Varchar', | ||
'MyInt' => 'Int', | ||
]; | ||
|
||
public function validate(ValidationResult $result) | ||
{ | ||
if ($this->owner->Title == 'x') { | ||
$result->addFieldError('Title', 'Title cannot be x'); | ||
} | ||
if ($this->owner->MyField == 'x') { | ||
$result->addFieldError('MyField', 'MyField cannot be x'); | ||
} | ||
if ($this->owner->Title == 'z' && $this->owner->MyField == 'z') { | ||
$result->addError('This is a general error message'); | ||
} | ||
} | ||
|
||
public function updateCMSCompositeValidator(CompositeValidator $compositeValidator) | ||
{ | ||
$compositeValidator->addValidator(new RequiredFields(['Title'])); | ||
} | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->removeByName('HTML'); | ||
$fields->addFieldToTab('Root.Main', TextField::create('MyField', 'My Field')); | ||
$fields->addFieldToTab('Root.Main', NumericField::create('MyInt', 'My Int')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace SilverStripe\FrameworkTest\Elemental\Extension; | ||
|
||
use SilverStripe\Forms\NumericField; | ||
use SilverStripe\Core\Extension; | ||
|
||
/** | ||
* @extends Extension<NumericField> | ||
*/ | ||
class NumericFieldExtension extends Extension | ||
{ | ||
public function updateValidationResult($result, $validator) | ||
{ | ||
if ($this->owner->Value() == 1) { | ||
$validator->validationError($this->owner->getName(), 'This field cannot be 1'); | ||
} | ||
} | ||
} |