WidgetFormBuilder::setDashboard()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php namespace Anomaly\DashboardModule\Widget\Form;
2
3
use Anomaly\DashboardModule\Dashboard\Contract\DashboardInterface;
4
use Anomaly\DashboardModule\Widget\Extension\WidgetExtension;
5
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
6
7
/**
8
 * Class WidgetFormBuilder
9
 *
10
 * @link          http://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 */
14
class WidgetFormBuilder extends FormBuilder
15
{
16
17
    /**
18
     * The widget instance.
19
     *
20
     * @var null|WidgetExtension
21
     */
22
    protected $extension = null;
23
24
    /**
25
     * The dashboard instance.
26
     *
27
     * @var null|DashboardInterface
28
     */
29
    protected $dashboard = null;
30
31
    /**
32
     * The skipped fields.
33
     *
34
     * @var array
35
     */
36
    protected $skips = [
37
        'extension',
38
        'column',
39
    ];
40
41
    /**
42
     * Fired when the form is ready to build.
43
     *
44
     * @throws \Exception
45
     */
46
    public function onReady()
47
    {
48
        if (!$this->getExtension() && !$this->getEntry()) {
49
            throw new \Exception('The $extension parameter is required when creating a page.');
50
        }
51
    }
52
53
    /**
54
     * Fired just before saving the form.
55
     */
56
    public function onSaving()
57
    {
58
        $entry     = $this->getFormEntry();
59
        $extension = $this->getExtension();
60
61
        if (!$entry->getId()) {
62
            $entry->extension = $extension->getNamespace();
63
        }
64
    }
65
66
    /**
67
     * Get the extension.
68
     *
69
     * @return null|WidgetExtension
70
     */
71
    public function getExtension()
72
    {
73
        return $this->extension;
74
    }
75
76
    /**
77
     * Set the extension.
78
     *
79
     * @param  WidgetExtension $extension
80
     * @return $this
81
     */
82
    public function setExtension(WidgetExtension $extension)
83
    {
84
        $this->extension = $extension;
85
86
        return $this;
87
    }
88
89
    /**
90
     * Get the dashboard.
91
     *
92
     * @return null|DashboardInterface
93
     */
94
    public function getDashboard()
95
    {
96
        return $this->dashboard;
97
    }
98
99
    /**
100
     * Set the dashboard.
101
     *
102
     * @param  DashboardInterface $dashboard
103
     * @return $this
104
     */
105
    public function setDashboard(DashboardInterface $dashboard)
106
    {
107
        $this->dashboard = $dashboard;
108
109
        return $this;
110
    }
111
}
112