Author: Shea Dawson (shea@livesource.co.nz)
Inheritance: extends GridFieldConfig
 /**
  * @return Form
  **/
 public function getEditForm($id = null, $fields = null)
 {
     Versioned::reading_stage('Stage');
     $form = parent::getEditForm($id, $fields);
     if ($blockGridField = $form->Fields()->fieldByName('Block')) {
         $blockGridField->setConfig(GridFieldConfig_BlockManager::create(true, true, false));
         $config = $blockGridField->getConfig();
         $dcols = $config->getComponentByType('GridFieldDataColumns');
         $dfields = $dcols->getDisplayFields($blockGridField);
         unset($dfields['BlockArea']);
         $dcols->setDisplayFields($dfields);
     }
     return $form;
 }
 /**
  * Block manager for Pages
  * */
 public function updateCMSFields(FieldList $fields)
 {
     if ($fields->fieldByName('Root.Blocks') || in_array($this->owner->ClassName, $this->blockManager->getExcludeFromPageTypes()) || !$this->owner->exists()) {
         return;
     }
     if (!Permission::check('BLOCK_EDIT')) {
         return;
     }
     if (!$this->blockManager->getIncludeFromPageTypes() || in_array($this->owner->ClassName, $this->blockManager->getIncludeFromPageTypes())) {
         $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);
         if ($areas && count($areas)) {
             $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton()));
             // Blocks related directly to this Page
             $gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)->addExisting($this->owner->class)->addComponent(new GridFieldOrderableRows());
             // TODO it seems this sort is not being applied...
             $gridSource = $this->owner->Blocks();
             // ->sort(array(
             // 	"FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '',
             // 	'SiteTree_Blocks.Sort' => 'ASC',
             // 	'Name' => 'ASC'
             // ));
             $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', 'Blocks', $gridSource, $gridConfig));
             // Blocks inherited from BlockSets
             if ($this->blockManager->getUseBlockSets()) {
                 $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true);
                 if ($inheritedBlocks->count()) {
                     $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false);
                     if ($activeInherited->count()) {
                         $fields->addFieldsToTab('Root.Blocks', array(GridField::create('InheritedBlockList', 'Blocks Inherited from Block Sets', $activeInherited, GridFieldConfig_BlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>Tip: Inherited blocks can be edited in the <a href='admin/block-admin'>Block Admin area</a><p>")));
                     }
                     $fields->addFieldToTab('Root.Blocks', ListBoxField::create('DisabledBlocks', 'Disable Inherited Blocks', $inheritedBlocks->map('ID', 'Title'), null, null, true)->setDescription('Select any inherited blocks that you would not like displayed on this page.'));
                 } else {
                     $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', 'Disable Inherited Blocks', 'This page has no inherited blocks to disable.'));
                 }
                 $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', 'Inherit Blocks from Block Sets'));
             }
         } else {
             $fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', 'This page type has no Block Areas configured.'));
         }
     } else {
         return;
     }
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeFieldFromTab('Root', 'PageParents');
     $fields->addFieldToTab('Root.Main', HeaderField::create('SettingsHeading', _t('BlockSet.Settings', 'Settings')), 'Title');
     $fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', _t('BlockSet.OnlyApplyToThesePageTypes', 'Only apply to these Page Types:'), $this->pageTypeOptions())->setDescription(_t('BlockSet.OnlyApplyToThesePageTypesDescription', 'Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.')));
     $fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', _t('BlockSet.OnlyApplyToChildrenOfThesePages', 'Only apply to children of these Pages:'), 'SiteTree'));
     $fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', _t('BlockSet.ApplyBlockSetToSelectedPageParentsAsWellAsChildren', 'Apply block set to selected page parents as well as children')));
     if (!$this->ID) {
         $fields->addFieldToTab('Root.Main', LiteralField::create('NotSaved', "<p class='message warning'>" . _t('BlockSet.YouCanAddBlocksToThisSetOnceYouHaveSavedIt', 'You can add Blocks to this set once you have saved it for the first time') . '</p>'));
         return $fields;
     }
     $fields->removeFieldFromTab('Root', 'Blocks');
     $gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true, true)->addExisting()->addComponent(new GridFieldOrderableRows());
     $gridSource = $this->Blocks()->Sort('Sort');
     $fields->addFieldToTab('Root.Main', HeaderField::create('BlocksHeading', _t('Block.PLURALNAME', 'Blocks')));
     $fields->addFieldToTab('Root.Main', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));
     return $fields;
 }
 /**
  * Block manager for Pages.
  * */
 public function updateCMSFields(FieldList $fields)
 {
     if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) {
         return;
     }
     $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);
     if ($areas && count($areas)) {
         $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks')));
         if (BlockManager::config()->get('block_area_preview')) {
             $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton()));
         }
         // Blocks related directly to this Page
         $gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)->addExisting($this->owner->class)->addComponent(new GridFieldOrderableRows());
         // TODO it seems this sort is not being applied...
         $gridSource = $this->owner->Blocks();
         // ->sort(array(
         // 	"FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '',
         // 	'SiteTree_Blocks.Sort' => 'ASC',
         // 	'Name' => 'ASC'
         // ));
         $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));
         // Blocks inherited from BlockSets
         if ($this->blockManager->getUseBlockSets()) {
             $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true);
             if ($inheritedBlocks->count()) {
                 $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false);
                 if ($activeInherited->count()) {
                     $fields->addFieldsToTab('Root.Blocks', array(GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, GridFieldConfig_BlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>" . _t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', array('link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>')) . '<p>')));
                 }
                 $fields->addFieldToTab('Root.Blocks', ListBoxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), $inheritedBlocks->map('ID', 'Title'), null, null, true)->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.')));
             } else {
                 $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable', 'This page has no inherited blocks to disable.')));
             }
             $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets')));
         }
     }
 }