Completed
Push — master ( 8ab7cc...28fbef )
by Garion
03:38
created

NewsPage::getNewsPageAuthor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace CWP\CWP\PageTypes;
4
5
use SilverStripe\AssetAdmin\Forms\UploadField;
0 ignored issues
show
Bug introduced by
The type SilverStripe\AssetAdmin\Forms\UploadField was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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