1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Navigation; |
4
|
|
|
|
5
|
|
|
use SleepingOwl\Admin\Contracts\Navigation\PageInterface; |
6
|
|
|
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface; |
7
|
|
|
|
8
|
|
|
class Page extends \KodiComponents\Navigation\Page implements PageInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Menu item related model class. |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Menu item by url id. |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $aliasId; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string|null $modelClass |
24
|
|
|
*/ |
25
|
|
|
public function __construct($modelClass = null) |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
|
29
|
|
|
$this->setModel($modelClass); |
30
|
|
|
|
31
|
|
|
if ($this->hasModel()) { |
32
|
|
|
$this->setIcon($this->getModelConfiguration()->getIcon()); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setIcon($icon) |
37
|
|
|
{ |
38
|
|
|
$this->icon = $icon; |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Set Alias Id. |
45
|
|
|
*/ |
46
|
|
|
public function setAliasId() |
47
|
|
|
{ |
48
|
|
|
$url = parse_url($this->getUrl(), PHP_URL_PATH); |
49
|
|
|
if ($url) { |
50
|
|
|
$this->aliasId = md5($url); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getAliasId() |
58
|
|
|
{ |
59
|
|
|
return $this->aliasId; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return ModelConfigurationInterface |
64
|
|
|
*/ |
65
|
|
|
public function getModelConfiguration() |
66
|
|
|
{ |
67
|
|
|
if (! $this->hasModel()) { |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return app('sleeping_owl')->getModel($this->model); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function hasModel() |
78
|
|
|
{ |
79
|
|
|
return ! is_null($this->model) && class_exists($this->model); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getId() |
86
|
|
|
{ |
87
|
|
|
if (is_null($this->id) && $this->hasModel()) { |
|
|
|
|
88
|
|
|
return $this->model; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return parent::getId(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getTitle() |
98
|
|
|
{ |
99
|
|
|
if (is_null($this->title) && $this->hasModel()) { |
|
|
|
|
100
|
|
|
return $this->getModelConfiguration()->getTitle(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return parent::getTitle(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getUrl() |
110
|
|
|
{ |
111
|
|
|
if (is_null($this->url) && $this->hasModel()) { |
|
|
|
|
112
|
|
|
return $this->getModelConfiguration()->getDisplayUrl(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return parent::getUrl(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return \Closure |
120
|
|
|
*/ |
121
|
|
|
public function getAccessLogic() |
122
|
|
|
{ |
123
|
|
|
if (! is_callable($this->accessLogic)) { |
124
|
|
|
if ($this->hasModel()) { |
125
|
|
|
return function () { |
126
|
|
|
return $this->getModelConfiguration()->isDisplayable(); |
127
|
|
|
}; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return parent::getAccessLogic(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param string|null $view |
136
|
|
|
* |
137
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
138
|
|
|
*/ |
139
|
|
|
public function render($view = null) |
140
|
|
|
{ |
141
|
|
|
if ($this->hasChild() && ! $this->hasClassProperty($class = config('navigation.class.has_child', 'treeview'))) { |
142
|
|
|
$this->setHtmlAttribute('class', $class); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$data = $this->toArray(); |
146
|
|
|
|
147
|
|
|
if (! is_null($view)) { |
148
|
|
|
return view($view, $data)->render(); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return app('sleeping_owl.template')->view('_partials.navigation.page', $data)->render(); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param string $model |
156
|
|
|
* |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
protected function setModel($model) |
160
|
|
|
{ |
161
|
|
|
$this->model = $model; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.