mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
59 lines
1.5 KiB
PHP
Executable File
59 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace A2nt\CMSNiceties\Widgets;
|
|
|
|
use DNADesign\Elemental\Forms\ElementalAreaField;
|
|
use SilverStripe\Forms\FieldList;
|
|
use SilverStripe\Forms\LiteralField;
|
|
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
|
use SilverStripe\Widgets\Model\Widget;
|
|
use SilverStripe\Widgets\Model\WidgetArea;
|
|
|
|
/**
|
|
* Class \A2nt\CMSNiceties\Widgets\WidgetPageExtension
|
|
*
|
|
* @property \A2nt\CMSNiceties\Widgets\WidgetPageExtension $owner
|
|
*/
|
|
class WidgetPageExtension extends \SilverStripe\Widgets\Extensions\WidgetPageExtension
|
|
{
|
|
public function updateCMSFields(FieldList $fields)
|
|
{
|
|
parent::updateCMSFields($fields);
|
|
|
|
$tab = $fields->findOrMakeTab('Root.Widgets');
|
|
|
|
$tab->setTitle('Sidebar');
|
|
|
|
$tab->removeByName('SideBar');
|
|
|
|
$widgetTypes = WidgetAreaEditor::create('Sidebar')->AvailableWidgets();
|
|
$available = [];
|
|
/** @var Widget $type */
|
|
foreach ($widgetTypes as $type) {
|
|
$available[get_class($type)] = $type->getCMSTitle();
|
|
}
|
|
|
|
$w = $this->owner->Sidebar();
|
|
$tab->push(WidgetAreaField::create(
|
|
'SideBar',
|
|
$w,
|
|
$available
|
|
));
|
|
}
|
|
|
|
public function onBeforeWrite()
|
|
{
|
|
parent::onBeforeWrite();
|
|
|
|
$obj = $this->owner;
|
|
$w = $obj->SideBar();
|
|
|
|
if (!$w->ID || !$obj->getField('SideBarID')) {
|
|
$area = WidgetArea::create();
|
|
$area->write();
|
|
|
|
$obj->setField('SideBarID', $area->ID);
|
|
}
|
|
}
|
|
}
|