/** * 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; } $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); if ($areas && count($areas)) { $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME'))); 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'))); } } else { $fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', _t('BlocksSiteTreeExtension.NoBlockAreasConfigured', 'This page type has no Block Areas configured.'))); } }
public function getCMSFields() { $self = $this; $this->beforeUpdateCMSFields(function ($fields) use($self) { /** @var FieldList $fields */ Requirements::add_i18n_javascript(BLOCKS_DIR . '/javascript/lang'); // this line is a temporary patch until I can work out why this dependency isn't being // loaded in some cases... if (!$self->blockManager) { $self->blockManager = singleton('BlockManager'); } // ClassNmae - block type/class field $classes = $self->blockManager->getBlockClasses(); $fields->addFieldToTab('Root.Main', DropdownField::create('ClassName', _t('Block.BlockType', 'Block Type'), $classes)->addExtraClass('block-type'), 'Title'); // BlockArea - display areas field if on page edit controller if (Controller::curr()->class == 'CMSPageEditController') { $currentPage = Controller::curr()->currentPage(); $areas = $self->blockManager->getAreasForPageType($currentPage->ClassName); $fields->addFieldToTab('Root.Main', $blockAreaField = DropdownField::create('ManyMany[BlockArea]', _t('Block.BlockArea', 'Block Area'), $areas), 'ClassName'); if (count($areas) > 1) { $blockAreaField->setEmptyString('(Select one)'); } if (BlockManager::config()->get('block_area_preview')) { $blockAreaField->setRightTitle($currentPage->areasPreviewButton()); } } $fields->removeFieldFromTab('Root', 'BlockSets'); $fields->removeFieldFromTab('Root', 'Pages'); // legacy fields, will be removed in later release $fields->removeByName('Weight'); $fields->removeByName('Area'); $fields->removeByName('Published'); if ($self->blockManager->getUseExtraCSSClasses()) { $fields->addFieldToTab('Root.Main', $fields->dataFieldByName('ExtraCSSClasses'), 'Title'); } else { $fields->removeByName('ExtraCSSClasses'); } // Viewer groups $fields->removeFieldFromTab('Root', 'ViewerGroups'); $groupsMap = Group::get()->map('ID', 'Breadcrumbs')->toArray(); asort($groupsMap); $viewersOptionsField = new OptionsetField('CanViewType', _t('SiteTree.ACCESSHEADER', 'Who can view this page?')); $viewerGroupsField = ListboxField::create('ViewerGroups', _t('SiteTree.VIEWERGROUPS', 'Viewer Groups'))->setMultiple(true)->setSource($groupsMap)->setAttribute('data-placeholder', _t('SiteTree.GroupPlaceholder', 'Click to select group')); $viewersOptionsSource = array(); $viewersOptionsSource['Anyone'] = _t('SiteTree.ACCESSANYONE', 'Anyone'); $viewersOptionsSource['LoggedInUsers'] = _t('SiteTree.ACCESSLOGGEDIN', 'Logged-in users'); $viewersOptionsSource['OnlyTheseUsers'] = _t('SiteTree.ACCESSONLYTHESE', 'Only these people (choose from list)'); $viewersOptionsField->setSource($viewersOptionsSource)->setValue('Anyone'); $fields->addFieldToTab('Root', new Tab('ViewerGroups', _t('Block.ViewerGroups', 'Viewer Groups'))); $fields->addFieldsToTab('Root.ViewerGroups', array($viewersOptionsField, $viewerGroupsField)); // Disabled for now, until we can list ALL pages this block is applied to (inc via sets) // As otherwise it could be misleading // Show a GridField (list only) with pages which this block is used on // $fields->removeFieldFromTab('Root.Pages', 'Pages'); // $fields->addFieldsToTab('Root.Pages', // new GridField( // 'Pages', // 'Used on pages', // $self->Pages(), // $gconf = GridFieldConfig_Base::create())); // enhance gridfield with edit links to pages if GFEditSiteTreeItemButtons is available // a GFRecordEditor (default) combined with BetterButtons already gives the possibility to // edit versioned records (Pages), but STbutton loads them in their own interface instead // of GFdetailform // if(class_exists('GridFieldEditSiteTreeItemButton')) { // $gconf->addComponent(new GridFieldEditSiteTreeItemButton()); // } }); return parent::getCMSFields(); }