Completed
Push — master ( b847e9...aea582 )
by Ryan
02:11
created

WidgetExtension::content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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