Completed
Pull Request — master (#13)
by Robbie
02:33
created

NewsPage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 16 1
A fieldLabels() 0 7 1
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
10
class NewsPage extends DatedUpdatePage
11
{
12
    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...
13
14
    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...
15
16
    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...
17
18
    private static $icon = 'cwp/images/icons/sitetree_images/news.png';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
19
20
    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...
21
22
    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...
23
24
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
25
        'Author' => 'Varchar(255)',
26
    ];
27
28
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
29
        'FeaturedImage' => Image::class,
30
    ];
31
32
    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...
33
34
    public $pageIcon =  'images/icons/sitetree_images/news.png';
35
36
    public function fieldLabels($includerelations = true)
37
    {
38
        $labels = parent::fieldLabels($includerelations);
39
        $labels['Author'] = _t('DateUpdatePage.AuthorFieldLabel', 'Author');
40
        $labels['FeaturedImageID'] = _t('DateUpdatePage.FeaturedImageFieldLabel', 'Featured Image');
41
42
        return $labels;
43
    }
44
45
    public function getCMSFields()
46
    {
47
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
48
            $fields->addFieldToTab(
49
                'Root.Main',
50
                TextField::create('Author', $this->fieldLabel('Author')),
0 ignored issues
show
Bug introduced by
'Author' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
                TextField::create(/** @scrutinizer ignore-type */ 'Author', $this->fieldLabel('Author')),
Loading history...
51
                'Abstract'
52
            );
53
54
            $fields->addFieldToTab(
55
                'Root.Main',
56
                UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')),
57
                'Abstract'
58
            );
59
        });
60
        return parent::getCMSFields();
61
    }
62
}
63