From 6daf6f395956a6b7d6870f316178a44e02ea7dab Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 2 May 2024 11:57:46 +1200 Subject: [PATCH] NEW Add NonInlineEditableExtension --- code/TestRegistryPage.php | 2 +- code/elemental/ElementContentExtension.php | 7 ++++++- code/elemental/NonInlineEditableExtension.php | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 code/elemental/NonInlineEditableExtension.php 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) diff --git a/code/elemental/NonInlineEditableExtension.php b/code/elemental/NonInlineEditableExtension.php new file mode 100644 index 0000000..99969ee --- /dev/null +++ b/code/elemental/NonInlineEditableExtension.php @@ -0,0 +1,10 @@ +