|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* **BaseHomePage** is the basic home page. |
|
4
|
|
|
* By default it is hidden from the CMS - we rely on developers creating their own |
|
5
|
|
|
* `HomePage` class in the `mysite/code` which will extend from the **BaseHomePage**. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class BaseHomePage extends Page { |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
private static $icon = 'cwp/images/icons/sitetree_images/home.png'; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
private static $hide_ancestor = 'BaseHomePage'; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
private static $singular_name = 'Home Page'; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
private static $plural_name = 'Home Pages'; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
private static $db = array( |
|
|
|
|
|
|
19
|
|
|
'FeatureOneTitle' => 'Varchar(255)', |
|
20
|
|
|
'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
21
|
|
|
'FeatureOneContent' => 'HTMLText', |
|
22
|
|
|
'FeatureOneButtonText' => 'Varchar(255)', |
|
23
|
|
|
'FeatureTwoTitle' => 'Varchar(255)', |
|
24
|
|
|
'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
25
|
|
|
'FeatureTwoContent' => 'HTMLText', |
|
26
|
|
|
'FeatureTwoButtonText' => 'Varchar(255)' |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
30
|
|
|
'LearnMorePage' => 'SiteTree', |
|
31
|
|
|
'FeatureOneLink' => 'SiteTree', |
|
32
|
|
|
'FeatureTwoLink' => 'SiteTree' |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
private static $has_many = array( |
|
|
|
|
|
|
36
|
|
|
'Quicklinks' => 'Quicklink.Parent' |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
public $pageIcon = 'images/icons/sitetree_images/home.png'; |
|
40
|
|
|
|
|
41
|
|
|
public function Quicklinks() { |
|
42
|
|
|
return $this->getComponents('Quicklinks')->sort('SortOrder'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getCMSFields() { |
|
46
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
47
|
|
|
// Main Content tab |
|
48
|
|
|
$fields->addFieldToTab( |
|
49
|
|
|
'Root.Main', |
|
50
|
|
|
TreeDropdownField::create( |
|
51
|
|
|
'LearnMorePageID', |
|
52
|
|
|
_t('BaseHomePage.LearnMoreLink','Page to link the "Learn More" button to:'), |
|
53
|
|
|
'SiteTree' |
|
54
|
|
|
), |
|
55
|
|
|
'Metadata' |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$gridField = GridField::create( |
|
59
|
|
|
'Quicklinks', |
|
60
|
|
|
'Quicklinks', |
|
61
|
|
|
$this->Quicklinks(), |
|
62
|
|
|
GridFieldConfig_RelationEditor::create() |
|
63
|
|
|
); |
|
64
|
|
|
$gridConfig = $gridField->getConfig(); |
|
65
|
|
|
$gridConfig->getComponentByType('GridFieldAddNewButton')->setButtonName( |
|
|
|
|
|
|
66
|
|
|
_t('BaseHomePage.AddNewButton','Add new') |
|
67
|
|
|
); |
|
68
|
|
|
$gridConfig->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
69
|
|
|
$gridConfig->removeComponentsByType('GridFieldDeleteAction'); |
|
70
|
|
|
$gridConfig->addComponent(new GridFieldDeleteAction()); |
|
71
|
|
|
$gridConfig->addComponent(new GridFieldSortableRows('SortOrder')); |
|
|
|
|
|
|
72
|
|
|
$gridField->setModelClass('Quicklink'); |
|
73
|
|
|
|
|
74
|
|
|
$fields->addFieldToTab('Root.Quicklinks', $gridField); |
|
75
|
|
|
|
|
76
|
|
|
$fields->removeByName('Import'); |
|
77
|
|
|
|
|
78
|
|
|
$fields->addFieldToTab( |
|
79
|
|
|
'Root.Features', |
|
80
|
|
|
ToggleCompositeField::create('FeatureOne', _t('SiteTree.FeatureOne', 'Feature One'), |
|
81
|
|
|
array( |
|
82
|
|
|
TextField::create('FeatureOneTitle', _t('BaseHomePage.Title','Title')), |
|
83
|
|
|
$dropdownField = DropdownField::create( |
|
84
|
|
|
'FeatureOneCategory', |
|
85
|
|
|
_t('BaseHomePage.FeatureCategoryDropdown','Category icon'), |
|
86
|
|
|
singleton('BaseHomePage')->dbObject('FeatureOneCategory')->enumValues() |
|
87
|
|
|
), |
|
88
|
|
|
HTMLEditorField::create( |
|
89
|
|
|
'FeatureOneContent', |
|
90
|
|
|
_t('BaseHomePage.FeatureContentFieldLabel','Content') |
|
91
|
|
|
), |
|
92
|
|
|
TextField::create( |
|
93
|
|
|
'FeatureOneButtonText', |
|
94
|
|
|
_t('BaseHomePage.FeatureButtonText','Button text') |
|
95
|
|
|
), |
|
96
|
|
|
TreeDropdownField::create( |
|
97
|
|
|
'FeatureOneLinkID', |
|
98
|
|
|
_t('BaseHomePage.FeatureLink','Page to link to'), |
|
99
|
|
|
'SiteTree' |
|
100
|
|
|
)->setDescription(_t('BaseHomePage.ButtonTextRequired','Button text must be filled in')) |
|
101
|
|
|
) |
|
102
|
|
|
)->setHeadingLevel(3) |
|
103
|
|
|
); |
|
104
|
|
|
$dropdownField->setEmptyString('none'); |
|
105
|
|
|
|
|
106
|
|
|
$fields->addFieldToTab('Root.Features', ToggleCompositeField::create('FeatureTwo', _t('SiteTree.FeatureTwo', 'Feature Two'), |
|
107
|
|
|
array( |
|
108
|
|
|
TextField::create('FeatureTwoTitle', _t('BaseHomePage.Title','Title')), |
|
109
|
|
|
$dropdownField = DropdownField::create( |
|
110
|
|
|
'FeatureTwoCategory', |
|
111
|
|
|
_t('BaseHomePage.FeatureCategoryDropdown','Category icon'), |
|
112
|
|
|
singleton('BaseHomePage')->dbObject('FeatureTwoCategory')->enumValues() |
|
113
|
|
|
), |
|
114
|
|
|
HTMLEditorField::create( |
|
115
|
|
|
'FeatureTwoContent', |
|
116
|
|
|
_t('BaseHomePage.FeatureContentFieldLabel','Content') |
|
117
|
|
|
), |
|
118
|
|
|
TextField::create( |
|
119
|
|
|
'FeatureTwoButtonText', |
|
120
|
|
|
_t('BaseHomePage.FeatureButtonText','Button text') |
|
121
|
|
|
), |
|
122
|
|
|
TreeDropdownField::create( |
|
123
|
|
|
'FeatureTwoLinkID', |
|
124
|
|
|
_t('BaseHomePage.FeatureLink','Page to link to'), |
|
125
|
|
|
'SiteTree' |
|
126
|
|
|
)->setDescription(_t('BaseHomePage.ButtonTextRequired','Button text must be filled in')) |
|
127
|
|
|
) |
|
128
|
|
|
)->setHeadingLevel(3) |
|
129
|
|
|
); |
|
130
|
|
|
$dropdownField->setEmptyString('none'); |
|
131
|
|
|
}); |
|
132
|
|
|
|
|
133
|
|
|
return parent::getCMSFields(); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
class BaseHomePage_Controller extends Page_Controller { |
|
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
public function getNewsPage() { |
|
140
|
|
|
return NewsHolder::get_one('NewsHolder'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param int $amount The amount of items to provide. |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getNewsItems($amount = 2) { |
|
147
|
|
|
$newsHolder = $this->getNewsPage(); |
|
148
|
|
|
if ($newsHolder) { |
|
149
|
|
|
$controller = new NewsHolder_Controller($newsHolder); |
|
150
|
|
|
return $controller->Updates()->limit($amount); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths