-
Notifications
You must be signed in to change notification settings - Fork 27
/
NewsPage.php
80 lines (63 loc) · 2.01 KB
/
NewsPage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace CWP\CWP\PageTypes;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\FieldType\DBField;
class NewsPage extends DatedUpdatePage
{
private static $description = 'Describes an item of news';
private static $default_parent = 'NewsHolderPage';
private static $can_be_root = false;
private static $icon_class = 'font-icon-p-news-item';
private static $singular_name = 'News Page';
private static $plural_name = 'News Pages';
private static $db = [
'Author' => 'Varchar(255)',
];
private static $has_one = [
'FeaturedImage' => Image::class,
];
private static $owns = [
'FeaturedImage',
];
private static $table_name = 'NewsPage';
public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);
$labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author');
$labels['FeaturedImageID'] = _t(
'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel',
'Featured Image'
);
return $labels;
}
public function getCMSFields()
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->addFieldToTab(
'Root.Main',
TextField::create('Author', $this->fieldLabel('Author')),
'Abstract'
);
$fields->addFieldToTab(
'Root.Main',
UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')),
'Abstract'
);
});
return parent::getCMSFields();
}
/**
* Returns the Author DB field for this page type.
*
* Used to avoid conflicts with `Versioned::Author()`
*
* @return DBField
*/
public function getNewsPageAuthor()
{
return $this->dbObject('Author');
}
}