WidgetExtension::content()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Anomaly\DashboardModule\Widget\Extension;
2
3
use Anomaly\DashboardModule\Widget\Contract\WidgetInterface;
4
use Anomaly\DashboardModule\Widget\Extension\Command\GetOutput;
5
use Anomaly\DashboardModule\Widget\Extension\Command\SetContent;
6
use Anomaly\DashboardModule\Widget\Extension\Contract\WidgetExtensionInterface;
7
use Anomaly\Streams\Platform\Addon\Extension\Extension;
8
9
/**
10
 * Class WidgetExtension
11
 *
12
 * @link          http://pyrocms.com/
13
 * @author        PyroCMS, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 */
16
class WidgetExtension extends Extension implements WidgetExtensionInterface
17
{
18
19
    /**
20
     * The widget view.
21
     *
22
     * @var string
23
     */
24
    protected $view = null;
25
26
    /**
27
     * The contextual state.
28
     *
29
     * @var string
30
     */
31
    protected $context = 'primary';
32
33
    /**
34
     * The widget wrapper.
35
     *
36
     * @var string
37
     */
38
    protected $wrapper = 'anomaly.module.dashboard::admin/widgets/widget';
39
40
    /**
41
     * Return the widget output.
42
     *
43
     * @param  WidgetInterface                 $widget
44
     * @return \Illuminate\Contracts\View\View
45
     */
46
    public function output(WidgetInterface $widget)
47
    {
48
        $this->load($widget);
49
        $this->content($widget);
50
51
        return $this->dispatch(new GetOutput($widget));
52
    }
53
54
    /**
55
     * Load the widget data.
56
     *
57
     * @param WidgetInterface $widget
58
     */
59
    protected function load(WidgetInterface $widget)
60
    {
61
        //
62
    }
63
64
    /**
65
     * Set the widget content.
66
     *
67
     * @param WidgetInterface $widget
68
     */
69
    protected function content(WidgetInterface $widget)
70
    {
71
        $this->dispatch(new SetContent($widget));
72
    }
73
74
    /**
75
     * Get the view.
76
     *
77
     * @return string
78
     */
79
    public function getView()
80
    {
81
        return $this->view ?: $this->getNamespace('content');
82
    }
83
84
    /**
85
     * Set the view.
86
     *
87
     * @param $view
88
     * @return $this
89
     */
90
    public function setView($view)
91
    {
92
        $this->view = $view;
93
94
        return $this;
95
    }
96
97
    /**
98
     * Get the wrapper.
99
     *
100
     * @return string
101
     */
102
    public function getWrapper()
103
    {
104
        return $this->wrapper;
105
    }
106
107
    /**
108
     * Set the wrapper.
109
     *
110
     * @param $wrapper
111
     * @return $this
112
     */
113
    public function setWrapper($wrapper)
114
    {
115
        $this->wrapper = $wrapper;
116
117
        return $this;
118
    }
119
120
    /**
121
     * Get the contextual state.
122
     *
123
     * @return string
124
     */
125
    public function getContext()
126
    {
127
        return $this->context;
128
    }
129
130
    /**
131
     * Set the contextual state.
132
     *
133
     * @param $context
134
     * @return $this
135
     */
136
    public function setContext($context)
137
    {
138
        $this->context = $context;
139
140
        return $this;
141
    }
142
}
143