DatedUpdatePage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldLabels() 0 7 1
A populateDefaults() 0 6 3
A getCMSFields() 0 22 1
1
<?php
2
3
namespace CWP\CWP\PageTypes;
4
5
use Page;
0 ignored issues
show
Bug introduced by
The type Page 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\Forms\DatetimeField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\TextareaField;
9
use SilverStripe\ORM\FieldType\DBDatetime;
10
11
class DatedUpdatePage extends Page
12
{
13
    /**
14
     * Meant as an abstract base class.
15
     *
16
     * {@inheritDoc}
17
     */
18
    private static $hide_ancestor = DatedUpdatePage::class;
0 ignored issues
show
introduced by
The private property $hide_ancestor is not used, and could be removed.
Loading history...
19
20
    private static $singular_name = 'Dated Update 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 = 'Dated Update 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 $table_name = 'DatedUpdatePage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
25
26
    private static $defaults = [
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
27
        'ShowInMenus' => false,
28
    ];
29
30
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
31
        'Abstract' => 'Text',
32
        'Date' => 'Datetime',
33
    ];
34
35
    /**
36
     * Add the default for the Date being the current day.
37
     */
38
    public function populateDefaults()
39
    {
40
        parent::populateDefaults();
41
42
        if (!isset($this->Date) || $this->Date === null) {
43
            $this->Date = DBDatetime::now()->Format('y-MM-dd 09:00:00');
0 ignored issues
show
Bug Best Practice introduced by
The property Date does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
        }
45
    }
46
47
    public function fieldLabels($includerelations = true)
48
    {
49
        $labels = parent::fieldLabels($includerelations);
50
        $labels['Date'] = _t(__CLASS__ . '.DateLabel', 'Date');
51
        $labels['Abstract'] = _t(__CLASS__ . '.AbstractTextFieldLabel', 'Abstract');
52
53
        return $labels;
54
    }
55
56
    public function getCMSFields()
57
    {
58
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
59
            $fields->addFieldToTab(
60
                'Root.Main',
61
                $dateTimeField = DatetimeField::create('Date', $this->fieldLabel('Date')),
62
                'Content'
63
            );
64
65
            $fields->addfieldToTab(
66
                'Root.Main',
67
                $abstractField = TextareaField::create('Abstract', $this->fieldLabel('Abstract')),
68
                'Content'
69
            );
70
            $abstractField->setAttribute('maxlength', '160');
71
            $abstractField->setRightTitle(_t(
72
                __CLASS__ . '.AbstractDesc',
73
                'The abstract is used as a summary on the listing pages. It is limited to 160 characters.'
74
            ));
75
            $abstractField->setRows(6);
76
        });
77
        return parent::getCMSFields();
78
    }
79
}
80