Skip to content

Commit

Permalink
Fixed #2 by implemented Lumberjack the right way
Browse files Browse the repository at this point in the history
  • Loading branch information
robertvanlienden committed Mar 16, 2023
1 parent 8ec396b commit 4892eab
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
6 changes: 6 additions & 0 deletions _config/app.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
---
Name: silverstripeaddons
---
RobertVanLienden\SilverStripeAddons\Pages\ItemOverviewPage:
extensions:
- SilverStripe\Lumberjack\Model\LumberJack

Page:
extensions:
- RobertVanLienden\SilverStripeAddons\Extensions\PageExtension

PageController:
extensions:
- RobertVanLienden\SilverStripeAddons\Extensions\PageControllerExtension

Silverstripe\SiteConfig\SiteConfig:
extensions:
- RobertVanLienden\SilverStripeAddons\Extensions\SiteConfigExtension
6 changes: 5 additions & 1 deletion src/Pages/ItemDetailPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class ItemDetailPage extends \Page
private static string $icon_class = 'font-icon-p-article';
private static string $description = 'A portfolio item page';

private static bool $can_be_root = false;
private static $show_in_sitetree = false;

private static $can_be_root = false;

private static $allowed_children = [];

private static array $db = [
'ProjectSummary' => 'HTMLText',
Expand Down
67 changes: 39 additions & 28 deletions src/Pages/ItemOverviewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace RobertVanLienden\SilverStripeAddons\Pages;

use Restruct\GridFieldSiteTreeButtons\GridFieldAddNewSiteTreeItemButton;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeAddNewButton;
use SilverStripe\ORM\DataList;
use SilverStripe\Lumberjack\Forms\GridFieldConfig_Lumberjack;

/**
*
Expand All @@ -18,6 +20,10 @@ class ItemOverviewPage extends \Page
private static string $icon_class = 'font-icon-p-articles';
private static string $description = 'A page with an overview with your portfolio items.';

private static array $allowed_children = [
ItemDetailPage::class
];

private static array $db = [
'AllItemDetailPages' => 'Boolean',
];
Expand All @@ -28,38 +34,43 @@ class ItemOverviewPage extends \Page

public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->addFieldsToTab('Root.Main', [
CheckboxField::create('AllItemDetailPages', 'Display all item detail pages on this page')
->setDescription('By default a overview page only shows pages under THIS overview page. '),
], 'Title');

$itemGridConfig = GridFieldConfig_RecordEditor::create();
$this->beforeUpdateCMSFields(
function (FieldList $fields) {
$fields->addFieldsToTab('Root.Main', [
CheckboxField::create('AllItemDetailPages', 'Display all item detail pages on this page')
->setDescription('By default a overview page only shows pages under THIS overview page. '),
], 'Title');

//$itemGridConfig = GridFieldConfig_Lumberjack::create();

//if ($this->AllItemDetailPages === 0) {
// $fields->addFieldsToTab('Root.Items', [
// $this->createGridField('Items', ItemDetailPage::get()->where(['ParentID' => $this->ID])),
// ]);
//} else {
// $fields->addFieldsToTab('Root.Items', [
// $this->createGridField('Items', ItemDetailPage::get())
// ]);
//}
}
);

return parent::getCMSFields();
}

public function getLumberjackPagesForGridfield(): DataList
{
if ($this->AllItemDetailPages === 0) {
$fields->addFieldsToTab('Root.Items', [
GridField::create('ItemPages',
'Item detail pages',
ItemDetailPage::get()->where(['ParentID' => $this->ID]),
$itemGridConfig)
]);
} else {
$fields->addFieldsToTab('Root.Items', [
GridField::create('ItemPages',
'Item pages',
ItemDetailPage::get(),
$itemGridConfig)
]);
return ItemDetailPage::get()->where(['ParentID' => $this->ID]);
}


return $fields;
return ItemDetailPage::get();
}

private static array $allowed_children = [
ItemDetailPage::class
];
public function getLumberjackTitle(): string
{
return 'Items';
}

public function getItemPages(?string $limit = null, ?string $all = null): DataList
{
Expand Down

0 comments on commit 4892eab

Please sign in to comment.