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

ElementalEditor::getSchemaDataDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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