From 433028abeb9d4f6bc3d42f55780588d7d9287a54 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 2 May 2024 12:49:44 +1200 Subject: [PATCH 1/2] ENH Make ElementalContentExtension MyPage a required field --- code/TestRegistryPage.php | 2 +- code/elemental/ElementContentExtension.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/code/TestRegistryPage.php b/code/TestRegistryPage.php index 76bd6db..020a9b4 100644 --- a/code/TestRegistryPage.php +++ b/code/TestRegistryPage.php @@ -6,7 +6,7 @@ use SilverStripe\Security\DefaultAdminService; use SilverStripe\Security\Member; -if (!class_exists(RegistryPage::class)) { +if (class_exists(RegistryPage::class)) { class TestRegistryPage extends RegistryPage { public function requireDefaultRecords() diff --git a/code/elemental/ElementContentExtension.php b/code/elemental/ElementContentExtension.php index d3e7273..8609875 100644 --- a/code/elemental/ElementContentExtension.php +++ b/code/elemental/ElementContentExtension.php @@ -2,6 +2,7 @@ namespace SilverStripe\FrameworkTest\Elemental\Extension; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; use SilverStripe\ORM\ValidationResult; @@ -20,6 +21,10 @@ class ElementContentExtension extends Extension 'MyInt' => 'Int', ]; + private static $has_one = [ + 'MyPage' => SiteTree::class, + ]; + public function validate(ValidationResult $result) { if ($this->owner->Title == 'x') { @@ -35,7 +40,7 @@ public function validate(ValidationResult $result) public function updateCMSCompositeValidator(CompositeValidator $compositeValidator) { - $compositeValidator->addValidator(new RequiredFields(['Title'])); + $compositeValidator->addValidator(new RequiredFields(['Title', 'MyPageID'])); } public function updateCMSFields(FieldList $fields) From ebc198a7d47ef67f7645d33c7a25024116e2a5ea Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 8 May 2024 14:12:55 +1200 Subject: [PATCH 2/2] ENH Add MyFile to ElementContentExtension --- code/elemental/ElementContentExtension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/elemental/ElementContentExtension.php b/code/elemental/ElementContentExtension.php index 8609875..06145f7 100644 --- a/code/elemental/ElementContentExtension.php +++ b/code/elemental/ElementContentExtension.php @@ -2,6 +2,7 @@ namespace SilverStripe\FrameworkTest\Elemental\Extension; +use SilverStripe\Assets\File; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; @@ -23,6 +24,7 @@ class ElementContentExtension extends Extension private static $has_one = [ 'MyPage' => SiteTree::class, + 'MyFile' => File::class, ]; public function validate(ValidationResult $result) @@ -40,7 +42,7 @@ public function validate(ValidationResult $result) public function updateCMSCompositeValidator(CompositeValidator $compositeValidator) { - $compositeValidator->addValidator(new RequiredFields(['Title', 'MyPageID'])); + $compositeValidator->addValidator(new RequiredFields(['Title', 'MyPageID', 'MyFile'])); } public function updateCMSFields(FieldList $fields)