IMPR: Allow moving Sidebar into elements list

This commit is contained in:
Tony Air 2023-09-24 18:51:04 +02:00
parent bfdbf2dbfa
commit 0019e3e6fd

View File

@ -2,6 +2,7 @@
namespace A2nt\CMSNiceties\Extensions; namespace A2nt\CMSNiceties\Extensions;
use A2nt\ElementalBasics\Elements\SidebarElement;
use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\TextareaField;
use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
@ -40,6 +41,28 @@ class SiteTreeExtension extends DataExtension
} }
} }
public function ShowSidebar()
{
$obj = $this->owner;
if ($obj->ElementalArea()->Elements()->find('ClassName', SidebarElement::class)->first()) {
return false;
}
if ($obj->SideBarContent) {
return true;
}
if (method_exists($obj, 'SideBarView')) {
$view = $obj->SideBarView();
if ($view && $view->Widgets()->count()) {
return true;
}
}
return false;
}
public function onBeforeWrite() public function onBeforeWrite()
{ {
parent::onBeforeWrite(); parent::onBeforeWrite();