From 128981758dcaa3342478ae3bf3f6190ca3a2649d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 13 Jun 2024 11:55:04 +1200 Subject: [PATCH] FIX Set RelatedPages gridfield to be structural --- src/PageTypes/BasePage.php | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/PageTypes/BasePage.php b/src/PageTypes/BasePage.php index 76c417d..1d6aa91 100644 --- a/src/PageTypes/BasePage.php +++ b/src/PageTypes/BasePage.php @@ -17,6 +17,7 @@ use Symbiote\GridFieldExtensions\GridFieldOrderableRows; use TractorCow\Fluent\Model\Locale; use TractorCow\Fluent\State\FluentState; +use SilverStripe\Forms\FormField; /** * `BasePage` is a foundation page class which can be used for constructing your own page types. By default it is @@ -127,15 +128,22 @@ public function getCMSFields() 'Root.RelatedPages', _t(__CLASS__ . '.RelatedPages', 'Related pages') ); - $fields->addFieldToTab( - 'Root.RelatedPages', - GridField::create( - 'RelatedPages', - _t(__CLASS__ . '.RelatedPages', 'Related pages'), - $this->RelatedPagesThrough(), - $components - ) - ); + $args = [ + 'RelatedPages', + _t(__CLASS__ . '.RelatedPages', 'Related pages'), + $this->RelatedPagesThrough(), + $components + ]; + $gridField = GridField::create(...$args); + // If GridField has been replaced by Injector, use that + // Otherwise use anonymous class so that versioned-admin behat tests pass + // when running in kitchen-sink + if (get_class($gridField) === GridField::class) { + $gridField = new class (...$args) extends GridField { + protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_STRUCTURAL; + }; + } + $fields->addFieldToTab('Root.RelatedPages', $gridField); // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc) $hasMany = $this->hasMany();