From e2bdb0a67b4efd76884a0734877908d2c5e65718 Mon Sep 17 00:00:00 2001 From: Marco Crespi Date: Mon, 2 Jul 2018 17:10:31 +0200 Subject: [PATCH] fix(page-element): Fix children gridfield not showing --- src/PageElement.php | 12 ++++++------ src/PageSectionsExtension.php | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/PageElement.php b/src/PageElement.php index ab7d5e2..da6f48a 100755 --- a/src/PageElement.php +++ b/src/PageElement.php @@ -6,7 +6,6 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\ReadonlyField; -use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldConfig; use SilverStripe\Forms\GridField\GridFieldConfig_Base; use SilverStripe\Forms\GridField\GridFieldButtonRow; @@ -22,10 +21,12 @@ use SilverStripe\Versioned\Versioned; use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass; +use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; use UncleCheese\BetterButtons\Actions\PrevNext; use UncleCheese\BetterButtons\Actions\CustomAction; use UncleCheese\BetterButtons\Buttons\Save; use UncleCheese\BetterButtons\Buttons\SaveAndClose; +use SilverStripe\Forms\Tab; class PageElement extends DataObject { @@ -143,8 +144,7 @@ public function getChildrenGridField() { $addNewButton = new GridFieldAddNewMultiClass(); $addNewButton->setClasses($this->getAllowedPageElements()); - $autoCompl = new GridFieldAddExistingAutocompleter('buttons-before-right'); - $autoCompl->setResultsFormat('$Name ($ID)'); + $autoCompl = new GridFieldAddExistingSearchButton('buttons-before-right'); $autoCompl->setSearchList(PageElement::get()->exclude("ID", $this->getParentIDs())); $config = GridFieldConfig::create() @@ -158,7 +158,7 @@ public function getChildrenGridField() { ->addComponent(new GridFieldFooter()); $dataColumns->setFieldCasting(["GridFieldPreview" => "HTMLText->RAW"]); - return new GridField("Children", "Children", $this->Children(), $config); + return GridField::create("Child", "Children", $this->Children(), $config); } public function getGridFieldPreview() { @@ -193,8 +193,8 @@ public function getCMSFields() { $fields->removeByName('__Counter'); $fields->removeByName("Children"); - if ($this->ID && count(static::getAllowedPageElements())) { - $fields->addFieldToTab('Root.PageSections', $this->getChildrenGridField()); + if ($this->ID && count(static::getAllowedPageElements()) > 0) { + $fields->insertAfter("Main", Tab::create("Child", "Children", $this->getChildrenGridField())); } // Add our newest version as a readonly field diff --git a/src/PageSectionsExtension.php b/src/PageSectionsExtension.php index 82734ab..fbfd6a4 100755 --- a/src/PageSectionsExtension.php +++ b/src/PageSectionsExtension.php @@ -5,7 +5,6 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldConfig; use SilverStripe\Forms\GridField\GridFieldButtonRow; use SilverStripe\Forms\GridField\GridFieldToolbarHeader; @@ -18,6 +17,7 @@ use SilverStripe\Versioned\Versioned; use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass; +use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; class PageSectionsExtension extends DataExtension { @@ -108,14 +108,11 @@ public function updateCMSFields(FieldList $fields) { $addNewButton = new GridFieldAddNewMultiClass(); $addNewButton->setClasses($this->owner->getAllowedPageElements()); - $autoCompl = new GridFieldAddExistingAutocompleter('buttons-before-right'); - $autoCompl->setResultsFormat('$Name ($ID)'); - $config = GridFieldConfig::create() ->addComponent(new GridFieldButtonRow("before")) ->addComponent(new GridFieldToolbarHeader()) ->addComponent($dataColumns = new GridFieldDataColumns()) - ->addComponent($autoCompl) + ->addComponent(new GridFieldAddExistingSearchButton('buttons-before-right')) ->addComponent($addNewButton) ->addComponent(new GridFieldPageSectionsExtension($this->owner)) ->addComponent(new GridFieldDetailForm());