public function run($request) { // update block/set titles // Name field has been reverted back to Title // DB::query("update Block set Name = Title"); // DB::query("update BlockSet set Name = Title"); // update block areas DB::query("\n\t\t\tupdate SiteTree_Blocks\n\t\t\tleft join Block on SiteTree_Blocks.BlockID = Block.ID\n\t\t\tset BlockArea = Block.Area\n\t\t\twhere BlockID = Block.ID\n\t\t"); // update block sort DB::query("\n\t\t\tupdate SiteTree_Blocks\n\t\t\tleft join Block on SiteTree_Blocks.BlockID = Block.ID\n\t\t\tset Sort = Block.Weight\n\t\t\twhere BlockID = Block.ID\n\t\t"); echo "BlockAreas, Sort updated<br />"; // migrate global blocks $sc = SiteConfig::current_site_config(); if ($sc->Blocks()->Count()) { $set = BlockSet::get()->filter('Title', 'Global')->first(); if (!$set) { $set = BlockSet::create(array('Title' => 'Global')); $set->write(); } foreach ($sc->Blocks() as $block) { if (!$set->Blocks()->find('ID', $block->ID)) { $set->Blocks()->add($block, array('Sort' => $block->Weight, 'BlockArea' => $block->Area)); echo "Block #{$block->ID} added to Global block set<br />"; } } } // publish blocks $blocks = Block::get()->filter('Published', 1); foreach ($blocks as $block) { $block->publish('Stage', 'Live'); echo "Published Block #{$block->ID}<br />"; } }
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('TypeForGridfield' => array('title' => _t('Block.BlockType', 'Block Type'), 'field' => 'LiteralField'), 'Title' => array('title' => _t('Block.Title', 'Title'), 'field' => 'ReadonlyField'), 'BlockArea' => array('title' => _t('Block.BlockArea', 'Block Area') . ' ', 'callback' => function () use($areasFieldSource) { return DropdownField::create('BlockArea', 'Block Area', $areasFieldSource)->setHasEmptyDefault(true); }), 'isPublishedNice' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'ReadonlyField'), '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('singular_name' => _t('Block.BlockType', 'Block Type'), 'Title' => _t('Block.Title', 'Title'), 'BlockArea' => _t('Block.BlockArea', 'Block Area'), 'isPublishedNice' => _t('Block.IsPublishedField', 'Published'), '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)); } return $this; }
/** * Get Any BlockSets that apply to this page. * * @return ArrayList * */ public function getAppliedSets() { $list = ArrayList::create(); if (!$this->owner->InheritBlockSets) { return $list; } $sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')"); $ancestors = $this->owner->getAncestors()->column('ID'); foreach ($sets as $set) { $restrictedToParerentIDs = $set->PageParents()->column('ID'); if (count($restrictedToParerentIDs)) { // check whether the set should include selected parent, in which case check whether // it was in the restricted parents list. If it's not, or if include parentpage // wasn't selected, we check the ancestors of this page. if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) { $list->add($set); } else { if (count($ancestors)) { foreach ($ancestors as $ancestor) { if (in_array($ancestor, $restrictedToParerentIDs)) { $list->add($set); continue; } } } } } else { $list->add($set); } } return $list; }
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(); } // EDIT $blockTypeArray = $this->blockManager->getBlockClasses(); // /EDIT // EditableColumns only makes sense on Saveable parenst (eg Page), or inline changes won't be saved if ($editableRows) { // set project-dir in cookie to be accessible as fallback from js Cookie::set('js-project-dir', project(), 90, null, null, false, false); $this->addComponent($editable = new GridFieldEditableColumns()); $displayfields = array('ClassName' => array('title' => _t('Block.BlockType', 'Block Type') . ' ', 'callback' => function () use($blockTypeArray) { return DropdownField::create('ClassName', 'Block Type', $blockTypeArray)->addExtraClass('select2blocktype')->setAttribute('data-project-dir', project()); }), 'Title' => array('title' => _t('Block.TitleName', 'Block Name'), 'field' => 'TextField'), 'BlockArea' => array('title' => _t('Block.BlockArea', 'Block Area') . ' ', 'callback' => function () use($areasFieldSource) { return DropdownField::create('BlockArea', 'Block Area', $areasFieldSource)->setHasEmptyDefault(true); }), 'isPublishedNice' => array('title' => _t('Block.IsPublishedField', 'Published'), 'field' => 'ReadonlyField'), 'UsageListAsString' => array('title' => _t('Block.UsageListAsString', 'Used on'), 'field' => 'ReadonlyField')); 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); // EDIT $this->addComponent($erow = new EditableBlockRow()); // /EDIT } else { $this->addComponent($dcols = new GridFieldDataColumns()); $displayfields = array('singular_name' => _t('Block.BlockType', 'Block Type'), 'Title' => _t('Block.TitleName', 'Block Name'), 'BlockArea' => _t('Block.BlockArea', 'Block Area'), 'isPublishedNice' => _t('Block.IsPublishedField', 'Published'), 'UsageListAsString' => _t('Block.UsageListAsString', 'Used on')); $dcols->setDisplayFields($displayfields); $dcols->setFieldCasting(array('UsageListAsString' => 'HTMLText->Raw')); } $this->addComponent(new GridFieldButtonRow('before')); // EDIT $this->addComponent(new GridFieldButtonRow('after')); // /EDIT $this->addComponent(new GridFieldToolbarHeader()); $this->addComponent(new GridFieldDetailForm()); // EDIT //$this->addComponent($sort = new GridFieldSortableHeader()); //$this->addComponent($filter = new GridFieldFilterHeader()); //$this->addComponent(new GridFieldDetailForm()); //$filter->setThrowExceptionOnBadDataType(false); //$sort->setThrowExceptionOnBadDataType(false); // load enhancements module (eg inline editing etc, needs save action @TODO: move to SiteTree only? if (class_exists('GF_BlockEnhancements')) { $this->addComponent(new GF_BlockEnhancements()); } // stuff only for BlockAdmin if ($controllerClass == 'BlockAdmin') { $this->addComponent($sort = new GridFieldSortableHeader()); $sort->setThrowExceptionOnBadDataType(false); $this->addComponent($filter = new GridFieldFilterHeader()); $filter->setThrowExceptionOnBadDataType(false); } else { // only for GF on SiteTree $this->addComponent(new GridFieldTitleHeader()); $this->addComponent(new GridFieldFooter()); // groupable $this->addComponent(new GridFieldGroupable('BlockArea', 'Area', 'none', $areasFieldSource)); // var_dump($areasFieldSource); // // Get available Areas (for page) enhancements inactive when in ModelAdmin/BlockAdmin // if (Controller::curr() && Controller::curr()->class == 'CMSPageEditController') { // // Provide defined blockAreas to JS // $blockManager = Injector::inst()->get('BlockManager'); //// $blockAreas = $blockManager->getAreasForPageType( Controller::curr()->currentPage()->ClassName ); // $blockAreas = $blockManager->getAreasForPageType( Controller::curr()->currentPage()->ClassName ); // } } if ($canAdd) { $multiClass = new GridFieldAddNewMultiClass('after'); $classes = $this->blockManager->getBlockClasses(); $multiClass->setClasses($classes); $this->addComponent($multiClass); //$this->addComponent(new GridFieldAddNewButton()); } // /EDIT if ($controllerClass == 'BlockAdmin' && class_exists('GridFieldCopyButton')) { $this->addComponent(new GridFieldCopyButton()); } if ($canEdit) { $this->addComponent(new GridFieldEditButton()); } if ($canDelete) { $this->addComponent(new GridFieldDeleteAction(true)); } return $this; }