1 | <?php |
||
28 | class BlockSet extends DataObject implements PermissionProvider |
||
29 | { |
||
30 | /** |
||
31 | * @var array |
||
32 | **/ |
||
33 | private static $table_name = "BlockSet"; |
||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | **/ |
||
38 | private static $db = [ |
||
39 | 'Title' => 'Varchar(255)', |
||
40 | 'PageTypes' => MultiValueField::class, |
||
41 | 'IncludePageParent' => 'Boolean', |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | **/ |
||
47 | private static $many_many = [ |
||
48 | "Blocks" => Block::class, |
||
49 | "PageParents" => SiteTree::class, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | **/ |
||
55 | private static $many_many_extraFields = [ |
||
56 | 'Blocks' => [ |
||
57 | 'Sort' => 'Int', |
||
58 | 'BlockArea' => 'Varchar', |
||
59 | 'AboveOrBelow' => 'Varchar', |
||
60 | ], |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * @var array |
||
65 | **/ |
||
66 | private static $above_or_below_options = [ |
||
67 | 'Above' => 'Above Page Blocks', |
||
68 | 'Below' => 'Below Page Blocks', |
||
69 | ]; |
||
70 | |||
71 | public function getCMSFields() |
||
72 | { |
||
73 | $fields = parent::getCMSFields(); |
||
74 | |||
75 | $fields->removeFieldFromTab('Root', 'PageParents'); |
||
76 | |||
77 | $fields->addFieldToTab('Root.Main', HeaderField::create('SettingsHeading', _t('BlockSet.Settings', 'Settings')), 'Title'); |
||
78 | $fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', _t('BlockSet.OnlyApplyToThesePageTypes', 'Only apply to these Page Types:'), $this->pageTypeOptions()) |
||
79 | ->setDescription(_t('BlockSet.OnlyApplyToThesePageTypesDescription', 'Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.'))); |
||
80 | $fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', _t('BlockSet.OnlyApplyToChildrenOfThesePages', 'Only apply to children of these Pages:'), 'SilverStripe\\CMS\\Model\\SiteTree')); |
||
81 | $fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', _t('BlockSet.ApplyBlockSetToSelectedPageParentsAsWellAsChildren','Apply block set to selected page parents as well as children'))); |
||
82 | |||
83 | if (!$this->ID) { |
||
84 | $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>')); |
||
85 | |||
86 | return $fields; |
||
87 | } |
||
88 | |||
89 | $fields->removeFieldFromTab('Root', 'Blocks'); |
||
90 | |||
91 | /** |
||
92 | * @todo - change relation editor back to the custom block manager config and fix issues when 'creating' Blocks from a BlockSet. |
||
93 | */ |
||
94 | $gridConfig = GridFieldConfig_RelationEditor::create(); |
||
95 | $gridConfig->addComponent(new GridFieldOrderableRows('Sort')); |
||
96 | $gridConfig->addComponent(new GridFieldDeleteAction()); |
||
97 | |||
98 | $gridSource = $this->Blocks()->Sort('Sort'); |
||
99 | |||
100 | $fields->addFieldToTab('Root.Blocks', HeaderField::create('BlocksHeading', _t('Block.PLURALNAME', 'Blocks'))); |
||
101 | $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); |
||
102 | |||
103 | return $fields; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Returns a sorted array suitable for a dropdown with pagetypes and their translated name. |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | protected function pageTypeOptions() |
||
125 | |||
126 | /** |
||
127 | * Returns a list of pages this BlockSet features on. |
||
128 | * |
||
129 | * @return DataList |
||
130 | */ |
||
131 | public function Pages() |
||
146 | |||
147 | public function canView($member = null) |
||
151 | |||
152 | public function canEdit($member = null) |
||
156 | |||
157 | public function canDelete($member = null) |
||
161 | |||
162 | public function canCreate($member = null, $context = []) |
||
166 | |||
167 | public function providePermissions() |
||
184 | } |
||
185 |