ConfigurablePageFieldExtension::canEdit()   A
last analyzed

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
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * ConfigurablePageFieldExtension is an extension class that adds extra methods to the EditableField classes.
5
 *
6
 * @author  Mohamed Alsharaf <[email protected]>
7
 */
8
class ConfigurablePageFieldExtension extends DataExtension
9
{
10
    private static $belongs_many_many = [
11
        'Parents' => 'ConfigurablePage',
12
    ];
13
14
    /**
15
     * Get field value that is suitable for the view template file.
16
     *
17
     * @return object|false|string
18
     */
19 2
    public function getViewValue()
20
    {
21 2
        $class = $this->owner;
22
23
        // Header field only used in page type
24 2
        if ($class instanceof Moo_EditableFieldHeading) {
25 1
            return false;
26
        }
27
28
        // Default return string
29 1
        return (string) $this->owner->Value;
30
    }
31
32
    /**
33
     * Get string value of a field.
34
     *
35
     * @return null|string
36
     */
37 1
    public function getValueAsString()
38
    {
39 1
        return (string) $this->owner->Value;
40
    }
41
42
    /**
43
     * Format the field Title to be suitable as a variable in template.
44
     *
45
     * @return string
46
     */
47 2
    public function getViewFieldName()
48
    {
49 2
        return $this->owner->Name;
50
    }
51
52
    /**
53
     * Editable field can only be changed if is not part of a group.
54
     *
55
     * @param null $member
56
     *
57
     * @return bool
58
     */
59
    public function canEdit($member = null)
60
    {
61
        return (int) $this->owner->Group === 0;
62
    }
63
}
64