Source of file SidebarTemplate.php
Size: 3,118 Bytes - Last Modified: 2018-12-31T11:02:24+00:00
/var/www/docs.ssmods.com/process/src/code/dataobjects/SidebarTemplate.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | <?php class SidebarTemplate extends DataObject { private static $singular_name = 'Sidebar Template'; private static $plural_name = 'Sidebar Templates'; private static $db = [ 'Title' => 'Varchar(255)', 'PageType' => 'Varchar(255)' ]; private static $has_one = [ 'SiteConfig' => 'SiteConfig' ]; private static $many_many = [ 'SidebarWidgets' => 'SidebarWidget' ]; private static $many_many_extraFields = [ 'SidebarWidgets' => ['SortOrder' => 'Int'] ]; private static $summary_fields = [ 'Title' => 'Titel', 'PageType' => 'Seitentyp', 'SidebarWidgets.Count' => 'Widgets' ]; public function onBeforeWrite() { parent::onBeforeWrite(); $this->Title = 'Sidebar "' . $this->PageType . '" Template'; } public function canCreate($member = null) { $can = Permission::check(['ADMIN', 'CMS_ACCESS_LeftAndMain', 'SITETREE_VIEW_ALL']); return $can; } public function canEdit($member = null) { $can = Permission::check(['ADMIN', 'CMS_ACCESS_LeftAndMain', 'SITETREE_VIEW_ALL']); return $can; } public function canDelete($member = null) { $can = Permission::check(['ADMIN', 'CMS_ACCESS_LeftAndMain', 'SITETREE_VIEW_ALL']); return $can; } public function canView($member = null) { return true; } public function validate() { $result = parent::validate(); if(SidebarTemplate::get()->exclude('ID', $this->ID)->find('PageType', $this->PageType)) { $result->error('Ein Sidebar Template für diesen Seitentyp existiert bereits.'); } return $result; } private static $better_buttons_actions = array ( 'syncPages' ); public function getBetterButtonsActions() { $fields = parent::getBetterButtonsActions(); if($this->ID) { $fields->push(BetterButtonCustomAction::create('syncPages', 'Synchronisieren')); } return $fields; } public function syncPages() { if($className = $this->PageType) { $pages = $className::get()->filter('ClassName', $className); foreach($pages as $page) { $page->addSidebarWidgets($this); $page->removeSidebarWidgets($this); } return 'Sidebar Widgets wurden über alle Seiten vom Typ "' . $this->PageType . '" hinweg synchronisiert.'; } } public function getCMSFields() { $pageTypeSrc = ClassInfo::subclassesFor('Page'); $fields = FieldList::create( TabSet::create('Root', Tab::create('Main', 'Hauptteil', DropdownField::create('PageType', 'Seitentyp', $pageTypeSrc), GridField::create('SidebarWidgets', 'Widgets', $this->owner->SidebarWidgets(), $gc = SidebarGridConfig::create(30, 'SortOrder')) ) ) ); if(!$this->ID) { $fields->removeByName('SidebarWidgets'); $fields->insertAfter(LiteralField::create('Notice', '<div class="message notice">Nach dem speichern können Widgets hinzugefügt werden.</div>'), 'PageType'); } else { $gc->set(['relation', 'multi']); } return $fields; } } |