Cancelled
Push — master ( b1ac67...38ef72 )
by Nic
111:57 queued 111:57
created

PageSectionObject::canDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Class PageSectionObject
5
 *
6
 * @property string $Name
7
 * @property string $Title
8
 * @property HTMLText $Content
9
 * @property int $SortOrder
10
 * @property int $ImageID
11
 * @property int $PageSectionBlockID
12
 */
13
class PageSectionObject extends DataObject
14
{
15
    /**
16
     * @return string
17
     */
18
    private static $singular_name = 'Page Section';
19
20
    /**
21
     * @return string
22
     */
23
    private static $plural_name = 'Page Sections';
24
25
    /**
26
     * @var array
27
     */
28
    private static $db = array(
29
        'Name' => 'Varchar(255)',
30
        'Title' => 'Varchar(255)',
31
        'Content' => 'HTMLText',
32
        'SortOrder' => 'Int',
33
    );
34
35
    /**
36
     * @var array
37
     */
38
    private static $has_one = array(
39
        'Image' => 'Image',
40
        'PageSectionBlock' => 'PageSectionBlock',
41
    );
42
43
    /**
44
     * @var string
45
     */
46
    private static $default_sort = 'Name ASC';
0 ignored issues
show
Unused Code introduced by
The property $default_sort is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
47
48
    /**
49
     * @var array
50
     */
51
    private static $summary_fields = array(
52
        'Image.CMSThumbnail' => 'Image',
53
        'Name' => 'Name',
54
        'Title' => 'Title',
55
    );
56
57
    /**
58
     * @var array
59
     */
60
    private static $searchable_fields = array(
61
        'Name' => 'Name',
62
        'Title' => 'Title',
63
    );
64
65
    /**
66
     * @return FieldList
67
     */
68
    public function getCMSFields()
69
    {
70
        $fields = parent::getCMSFields();
71
72
        $fields->removeByName(array(
73
            'PageSectionBlockID',
74
            'SortOrder',
75
        ));
76
77
        $fields->dataFieldByName('Name')->setDescription('For internal reference only');
78
79
        $image = $fields->dataFieldByName('Image');
80
        $image->setFolderName('Uploads/PageSections');
81
        $fields->insertBefore($image, 'Content');
0 ignored issues
show
Documentation introduced by
'Content' is of type string, but the function expects a object<FormField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
83
        return $fields;
84
    }
85
86
    /**
87
     * @return ValidationResult
88
     */
89
    public function validate()
90
    {
91
        $result = parent::validate();
92
93
        if (!$this->Name) {
94
            $result->error('Name is requied before you can save');
95
        }
96
97
        return $result;
98
    }
99
100
    /**
101
     * Set permissions, allow all users to access by default.
102
     * Override in descendant classes, or use PermissionProvider.
103
     */
104
105
    /**
106
     * @param null $member
107
     *
108
     * @return bool
109
     */
110
    public function canCreate($member = null)
111
    {
112
        return true;
113
    }
114
115
    /**
116
     * @param null $member
117
     *
118
     * @return bool
119
     */
120
    public function canView($member = null)
121
    {
122
        return true;
123
    }
124
125
    /**
126
     * @param null $member
127
     *
128
     * @return bool
129
     */
130
    public function canEdit($member = null)
131
    {
132
        return true;
133
    }
134
135
    /**
136
     * @param null $member
137
     *
138
     * @return bool
139
     */
140
    public function canDelete($member = null)
141
    {
142
        return true;
143
    }
144
}