Source of file GridfieldConfig_BBBlockManager.php
Size: 5,833 Bytes - Last Modified: 2021-12-23T10:52:14+00:00
/var/www/docs.ssmods.com/process/src/code/forms/GridfieldConfig_BBBlockManager.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | <?php /** * GridFieldConfig_BlockManager * Provides a reusable GridFieldConfig for managing Blocks. * * @author Shea Dawson <shea@livesource.co.nz> * @author Todd Hossack <todd@tiraki.com> (Customisations) */ class GridFieldConfig_BBBlockManager extends GridFieldConfig { public $blockManager; public function __construct($canAdd = true, $canEdit = true, $canDelete = true, $editableRows = false, $aboveOrBelow = false) { parent::__construct(); $this->blockManager = Injector::inst()->get('BlockManager'); $controllerClass = Controller::curr()->class; // Get available Areas (for page) or all in case of ModelAdmin if ($controllerClass == 'CMSPageEditController') { $currentPage = Controller::curr()->currentPage(); $areasFieldSource = $this->blockManager->getAreasForPageType($currentPage->ClassName); } else { $areasFieldSource = $this->blockManager->getAreasForTheme(); } // EditableColumns only makes sense on Saveable parenst (eg Page), or inline changes won't be saved if ($editableRows) { $this->addComponent($editable = new GridFieldEditableColumns()); $displayfields = array( 'ID' => array('title' => _t('Block.ID', 'ID'), 'field' => 'LiteralField'), 'Title' => array('title' => _t('Block.Title', 'Title'), 'field' => 'ReadonlyField'), 'TypeForGridfield' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'LiteralField'), 'BlockArea' => array( 'title' => _t('Block.BlockArea', 'Block Area').' ', // the s prevent wrapping of dropdowns 'callback' => function () use ($areasFieldSource) { $areasField = DropdownField::create('BlockArea', 'Block Area', $areasFieldSource); if (count($areasFieldSource) > 1) { $areasField->setHasEmptyDefault(true); } return $areasField; }, ), 'isPublishedIcon' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'LiteralField'), 'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'LiteralField'), ); if ($aboveOrBelow) { $displayfields['AboveOrBelow'] = array( 'title' => _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), 'callback' => function () { return DropdownField::create('AboveOrBelow', _t('GridFieldConfigBlockManager.AboveOrBelow', 'Above or Below'), BlockSet::config()->get('above_or_below_options')); }, ); } $editable->setDisplayFields($displayfields); } else { $this->addComponent($dcols = new GridFieldDataColumns()); $displayfields = array( 'ID' => array('title' => _t('Block.ID', 'ID'), 'field' => 'LiteralField'), 'Title' => _t('Block.Title', 'Title'), 'TypeForGridfield' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'LiteralField'), 'BlockArea' => _t('Block.BlockArea', 'Block Area'), 'isPublishedIcon' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'LiteralField'), 'UsageListAsString' => _t('Block.UsageListAsString', 'Used on'), ); $dcols->setDisplayFields($displayfields); $dcols->setFieldCasting(array('UsageListAsString' => 'HTMLText->Raw')); } $this->addComponent(new GridFieldButtonRow('before')); $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldDetailForm()); $this->addComponent($sort = new GridFieldSortableHeader()); $this->addComponent($filter = new GridFieldFilterHeader()); $this->addComponent(new GridFieldDetailForm()); if ($controllerClass == 'BlockAdmin' && class_exists('GridFieldCopyButton')) { $this->addComponent(new GridFieldCopyButton()); } $filter->setThrowExceptionOnBadDataType(false); $sort->setThrowExceptionOnBadDataType(false); if ($canAdd) { $multiClass = new GridFieldAddNewMultiClass(); $classes = $this->blockManager->getBlockClasses(); $multiClass->setClasses($classes); $this->addComponent($multiClass); //$this->addComponent(new GridFieldAddNewButton()); } if ($canEdit) { $this->addComponent(new GridFieldEditButton()); } if ($canDelete) { $this->addComponent(new GridFieldDeleteAction(true)); //$this->addComponent(new GridFieldDeleteAction(false)); } return $this; } /** * Add the GridFieldAddExistingSearchButton component to this grid config. * * @return $this **/ public function addExisting() { $classes = $this->blockManager->getBlockClasses(); $this->addComponent($add = new GridFieldAddExistingSearchButton()); $add->setSearchList(Block::get()->filter(array( 'ClassName' => array_keys($classes), ))); return $this; } /** * Add the GridFieldBulkManager component to this grid config. * * @return $this **/ public function addBulkEditing() { if (class_exists('GridFieldBulkManager')) { $this->addComponent(new GridFieldBulkManager()); } return $this; } } |