Skip to content

Commit

Permalink
fix(page-element): Fix children gridfield not showing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Jul 2, 2018
1 parent a886bb2 commit e2bdb0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/PageElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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()
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/PageSectionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +17,7 @@
use SilverStripe\Versioned\Versioned;

use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton;

class PageSectionsExtension extends DataExtension {

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit e2bdb0a

Please sign in to comment.