Passed
Pull Request — master (#277)
by Robbie
02:05
created

ElementalEditor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getArea() 0 3 1
A getTypes() 0 7 1
A setTypes() 0 5 1
A getSchemaDataDefaults() 0 5 1
1
<?php
2
3
namespace DNADesign\Elemental;
4
5
use DNADesign\Elemental\Models\ElementalArea;
6
use SilverStripe\Forms\FormField;
7
8
class ElementalEditor extends FormField
9
{
10
    /**
11
     * @var ElementalArea $area
12
     */
13
    protected $area;
14
15
    /**
16
     * @var array $type
17
     */
18
    protected $types = [];
19
20
    /**
21
     * @param string $name
22
     * @param ElementalArea $area
23
     */
24
    public function __construct($name, ElementalArea $area)
25
    {
26
        // By default, no need for a title on the editor. If there is more than one area then use `setTitle` to describe
27
        parent::__construct($name, '');
28
        $this->area = $area;
29
30
        $this->addExtraClass('element-editor__container');
31
    }
32
33
    /**
34
     * @param array $types
35
     *
36
     * @return $this
37
     */
38
    public function setTypes($types)
39
    {
40
        $this->types = $types;
41
42
        return $this;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getTypes()
49
    {
50
        $types = $this->types;
51
52
        $this->extend('updateGetTypes', $types);
53
54
        return $types;
55
    }
56
57
    /**
58
     * @return ElementalArea
59
     */
60
    public function getArea()
61
    {
62
        return $this->area;
63
    }
64
65
    public function getSchemaDataDefaults()
66
    {
67
        $schemaData = parent::getSchemaDataDefaults();
68
        $schemaData['page-id'] = $this->getArea()->getOwnerPage()->ID;
69
        return $schemaData;
70
    }
71
}
72