Source of file VirtualBlock.php
Size: 2,060 Bytes - Last Modified: 2021-12-24T06:34:31+00:00
/var/www/docs.ssmods.com/process/src/code/blocks/VirtualBlock.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?php /** * The Virtual Block follows the same logic as a "Virtual Page" in the CMS. * It can be used to copy a blocks content to another page (or even multiple times within the same page). */ class VirtualBlock extends Block { private static $has_one = array( 'OriginalBlock' => 'Block' ); public function getTitle() { if ($this->OriginalBlockID) { return $this->OriginalBlock()->Title; } return ''; } public function getCMSTitle() { if ($this->OriginalBlockID) { return _t('VirtualBlock.COPYOF', '(copy of)') . ' ' . $this->OriginalBlock()->Title; } return _t('VirtualBlock.NO_ORIGINAL', '(no original set)'); } public function getCMSFields() { $fields = FieldList::create(); $fields->push(TabSet::create('Root', $mainTab = new Tab('Main'))); $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); $blockList = Block::get()->exclude('ClassName', 'VirtualBlock'); // Apply the allowed blocks config to the virtual-block $allowed = $this->Parent()->config()->get('allowed_blocks'); if (is_array($allowed)) { $blockList = $blockList->filter(array('ClassName' => $allowed)); } $source = $blockList->sort('ParentID, SortOrder')->map('ID', 'FullTitle'); $fields->addFieldsToTab('Root.Main', array( ReadonlyField::create('Title', _t('Block.TITLE', 'Title'), $this->getTitle()), DropdownField::create('OriginalBlockID', _t('VirtualBlock.SELECT_ORIGINAL', 'Select original'), $source) )); $this->extend('updateCMSFields', $fields); return $fields; } public function CSSClass() { if ($this->OriginalBlockID) { return $this->OriginalBlock()->CSSClass(); } return parent::CSSClass(); } public function HTML() { if ($this->OriginalBlockID) { return $this->OriginalBlock()->HTML(); } return ''; } } |