1 | <?php |
||||||
2 | |||||||
3 | namespace SleepingOwl\Admin\Display; |
||||||
4 | |||||||
5 | use Closure; |
||||||
6 | use Illuminate\Contracts\Support\Renderable; |
||||||
7 | use Illuminate\Database\Eloquent\Model; |
||||||
8 | use Illuminate\Http\Request; |
||||||
9 | use SleepingOwl\Admin\Contracts\Display\DisplayInterface; |
||||||
10 | use SleepingOwl\Admin\Contracts\Display\TabInterface; |
||||||
11 | use SleepingOwl\Admin\Contracts\Form\FormInterface; |
||||||
12 | use SleepingOwl\Admin\Contracts\ModelConfigurationInterface; |
||||||
13 | use SleepingOwl\Admin\Model\SectionModelConfiguration; |
||||||
14 | use SleepingOwl\Admin\Traits\FormElements; |
||||||
15 | use SleepingOwl\Admin\Traits\VisibleCondition; |
||||||
16 | |||||||
17 | /** |
||||||
18 | * @property TabInterface[]|DisplayTabsCollection $elements |
||||||
19 | */ |
||||||
20 | class DisplayTabbed implements DisplayInterface, FormInterface |
||||||
21 | { |
||||||
22 | use FormElements, VisibleCondition, \SleepingOwl\Admin\Traits\Renderable; |
||||||
23 | |||||||
24 | /** |
||||||
25 | * @var string |
||||||
26 | */ |
||||||
27 | protected $view = 'display.tabbed'; |
||||||
28 | |||||||
29 | /** |
||||||
30 | * DisplayTabbed constructor. |
||||||
31 | * |
||||||
32 | * @param Closure|TabInterface[] $tabs |
||||||
33 | */ |
||||||
34 | public function __construct($tabs = null) |
||||||
35 | { |
||||||
36 | $this->elements = new DisplayTabsCollection(); |
||||||
37 | |||||||
38 | if (is_array($tabs) || is_callable($tabs)) { |
||||||
39 | $this->setTabs($tabs); |
||||||
40 | } |
||||||
41 | } |
||||||
42 | |||||||
43 | /** |
||||||
44 | * Initialize tabbed interface. |
||||||
45 | */ |
||||||
46 | public function initialize() |
||||||
47 | { |
||||||
48 | $this->initializeElements(); |
||||||
49 | |||||||
50 | $tabs = $this->getTabs(); |
||||||
51 | |||||||
52 | foreach ($tabs as $tab) { |
||||||
53 | if (method_exists($tab->getContent(), 'getElements')) { |
||||||
54 | $elements = $tab->getContent()->getElements(); |
||||||
55 | foreach ($elements as $element) { |
||||||
56 | if ($element instanceof self) { |
||||||
57 | foreach ($element->getTabs() as $subTab) { |
||||||
58 | if ($subTab->getName() == session('sleeping_owl_tab_id')) { |
||||||
59 | $tab->setActive(true); |
||||||
60 | $subTab->setActive(true); |
||||||
61 | } |
||||||
62 | } |
||||||
63 | } |
||||||
64 | } |
||||||
65 | } |
||||||
66 | |||||||
67 | if ($tab->getName() == session('sleeping_owl_tab_id')) { |
||||||
68 | $tab->setActive(true); |
||||||
69 | } |
||||||
70 | } |
||||||
71 | |||||||
72 | $activeTabs = $this->getTabs()->filter(function (TabInterface $tab) { |
||||||
73 | return $tab->isActive(); |
||||||
74 | })->count(); |
||||||
75 | |||||||
76 | if ($activeTabs === 0 && $firstTab = $this->getTabs()->first()) { |
||||||
77 | $firstTab->setActive(true); |
||||||
78 | } |
||||||
79 | } |
||||||
80 | |||||||
81 | /** |
||||||
82 | * @return Model $model|null |
||||||
83 | */ |
||||||
84 | public function getModel() |
||||||
85 | { |
||||||
86 | foreach ($this->getTabs() as $tab) { |
||||||
87 | if ($tab->getContent() instanceof FormInterface) { |
||||||
88 | return $tab->getContent()->getModel(); |
||||||
89 | } |
||||||
90 | } |
||||||
91 | } |
||||||
92 | |||||||
93 | /** |
||||||
94 | * @param string $class |
||||||
95 | * |
||||||
96 | * @return $this |
||||||
97 | */ |
||||||
98 | public function setModelClass($class) |
||||||
99 | { |
||||||
100 | $this->getTabs()->each(function (TabInterface $tab) use ($class) { |
||||||
101 | if ($tab instanceof DisplayInterface) { |
||||||
102 | $tab->setModelClass($class); |
||||||
103 | } |
||||||
104 | }); |
||||||
105 | |||||||
106 | return $this; |
||||||
107 | } |
||||||
108 | |||||||
109 | /** |
||||||
110 | * @return TabInterface[]|\SleepingOwl\Admin\Form\FormElementsCollection |
||||||
111 | */ |
||||||
112 | public function getTabs() |
||||||
113 | { |
||||||
114 | return $this->getElements(); |
||||||
115 | } |
||||||
116 | |||||||
117 | /** |
||||||
118 | * @param Closure|TabInterface[] $tabs |
||||||
119 | * |
||||||
120 | * @return $this |
||||||
121 | */ |
||||||
122 | public function setTabs($tabs) |
||||||
123 | { |
||||||
124 | if (is_callable($tabs)) { |
||||||
125 | $tabs = call_user_func($tabs, $this); |
||||||
126 | } |
||||||
127 | |||||||
128 | return $this->setElements($tabs); |
||||||
129 | } |
||||||
130 | |||||||
131 | /** |
||||||
132 | * @param array $elements |
||||||
133 | * |
||||||
134 | * @return $this |
||||||
135 | */ |
||||||
136 | public function setElements(array $elements) |
||||||
137 | { |
||||||
138 | foreach ($elements as $label => $tab) { |
||||||
139 | if ($tab instanceof TabInterface) { |
||||||
140 | $this->addElement($tab); |
||||||
141 | } else { |
||||||
142 | $this->appendTab($tab, $label); |
||||||
143 | } |
||||||
144 | } |
||||||
145 | |||||||
146 | return $this; |
||||||
147 | } |
||||||
148 | |||||||
149 | /** |
||||||
150 | * @param Renderable $display |
||||||
151 | * @param string $label |
||||||
152 | * @param bool|false $active |
||||||
153 | * |
||||||
154 | * @return DisplayTab |
||||||
155 | */ |
||||||
156 | public function appendTab(Renderable $display, $label, $active = false) |
||||||
157 | { |
||||||
158 | $this->addElement( |
||||||
159 | $tab = app('sleeping_owl.display')->tab($display, $label)->setActive($active) |
||||||
0 ignored issues
–
show
|
|||||||
160 | ); |
||||||
161 | |||||||
162 | return $tab; |
||||||
163 | } |
||||||
164 | |||||||
165 | /** |
||||||
166 | * @param TabInterface $element |
||||||
167 | * |
||||||
168 | * @return $this |
||||||
169 | */ |
||||||
170 | public function addElement(TabInterface $element) |
||||||
171 | { |
||||||
172 | $this->elements->push($element); |
||||||
173 | |||||||
174 | return $this; |
||||||
175 | } |
||||||
176 | |||||||
177 | /** |
||||||
178 | * @param string $action |
||||||
179 | * |
||||||
180 | * @return $this |
||||||
181 | */ |
||||||
182 | public function setAction($action) |
||||||
183 | { |
||||||
184 | $this->getTabs()->each(function (TabInterface $tab) use ($action) { |
||||||
185 | if ($tab instanceof FormInterface) { |
||||||
186 | $tab->setAction($action); |
||||||
187 | } |
||||||
188 | }); |
||||||
189 | |||||||
190 | return $this; |
||||||
191 | } |
||||||
192 | |||||||
193 | /** |
||||||
194 | * @param int $id |
||||||
195 | * |
||||||
196 | * @return $this |
||||||
197 | */ |
||||||
198 | public function setId($id) |
||||||
199 | { |
||||||
200 | $model_class = get_class($this->getModel()); |
||||||
201 | $this->getTabs()->each(function (TabInterface $tab) use ($id, $model_class) { |
||||||
202 | if ($tab instanceof FormInterface) { |
||||||
203 | if (! $tab->getExternalForm()) { |
||||||
0 ignored issues
–
show
The method
getExternalForm() does not exist on SleepingOwl\Admin\Contracts\Display\TabInterface . Since it exists in all sub-types, consider adding an abstract or default implementation to SleepingOwl\Admin\Contracts\Display\TabInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
getExternalForm() does not exist on SleepingOwl\Admin\Contracts\Form\FormInterface . It seems like you code against a sub-type of SleepingOwl\Admin\Contracts\Form\FormInterface such as SleepingOwl\Admin\Display\DisplayTab .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
204 | $tab_content = $tab->getContent(); |
||||||
205 | if ($tab_content instanceof FormInterface) { |
||||||
206 | $tab_model = $tab->getModel(); |
||||||
207 | $set_id = $model_class == get_class($tab_model); |
||||||
208 | $tab_model_section = \AdminSection::getModel($tab_model); |
||||||
0 ignored issues
–
show
The type
AdminSection was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
209 | if (is_object($tab_model_section) && $tab_model_section instanceof SectionModelConfiguration) { |
||||||
210 | $set_id = $set_id && $tab->getContent()->getAction() == $tab_model_section->getUpdateUrl($id); |
||||||
211 | } |
||||||
212 | if ($set_id) { |
||||||
213 | $tab->setId($id); |
||||||
214 | } |
||||||
215 | } |
||||||
216 | } |
||||||
217 | } |
||||||
218 | }); |
||||||
219 | |||||||
220 | return $this; |
||||||
221 | } |
||||||
222 | |||||||
223 | /** |
||||||
224 | * @param \Illuminate\Http\Request $request |
||||||
225 | * @param ModelConfigurationInterface $model |
||||||
226 | * |
||||||
227 | * @return void |
||||||
228 | */ |
||||||
229 | public function validateForm(Request $request, ModelConfigurationInterface $model = null) |
||||||
230 | { |
||||||
231 | $this->getTabs()->each(function ($tab) use ($request, $model) { |
||||||
232 | $tabId = $request->get('sleeping_owl_tab_id'); |
||||||
233 | |||||||
234 | if ($tab instanceof FormInterface && $tab->getName() == $tabId) { |
||||||
0 ignored issues
–
show
The method
getName() does not exist on SleepingOwl\Admin\Contracts\Form\FormInterface . It seems like you code against a sub-type of SleepingOwl\Admin\Contracts\Form\FormInterface such as SleepingOwl\Admin\Display\DisplayTab .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
235 | $tab->validateForm($request, $model); |
||||||
236 | } |
||||||
237 | }); |
||||||
238 | } |
||||||
239 | |||||||
240 | /** |
||||||
241 | * @param \Illuminate\Http\Request $request |
||||||
242 | * @param ModelConfigurationInterface $model |
||||||
243 | * |
||||||
244 | * @return void |
||||||
245 | */ |
||||||
246 | public function saveForm(Request $request, ModelConfigurationInterface $model = null) |
||||||
247 | { |
||||||
248 | $this->getTabs()->each(function (TabInterface $tab) use ($request, $model) { |
||||||
249 | $tabId = $request->get('sleeping_owl_tab_id'); |
||||||
250 | |||||||
251 | if ($tab instanceof FormInterface && $tab->getName() == $tabId) { |
||||||
252 | $tab->saveForm($request, $model); |
||||||
253 | } |
||||||
254 | }); |
||||||
255 | } |
||||||
256 | |||||||
257 | /** |
||||||
258 | * @return null |
||||||
259 | */ |
||||||
260 | public function getValue() |
||||||
261 | { |
||||||
262 | } |
||||||
263 | |||||||
264 | /** |
||||||
265 | * @return bool |
||||||
266 | */ |
||||||
267 | public function isReadonly() |
||||||
268 | { |
||||||
269 | return false; |
||||||
270 | } |
||||||
271 | |||||||
272 | /** |
||||||
273 | * @return bool |
||||||
274 | */ |
||||||
275 | public function isValueSkipped() |
||||||
276 | { |
||||||
277 | return false; |
||||||
278 | } |
||||||
279 | |||||||
280 | /** |
||||||
281 | * @return array |
||||||
282 | */ |
||||||
283 | public function toArray() |
||||||
284 | { |
||||||
285 | return [ |
||||||
286 | 'tabs' => $this->getTabs()->onlyVisible(), |
||||||
287 | ]; |
||||||
288 | } |
||||||
289 | |||||||
290 | /** |
||||||
291 | * Using in trait FormElements;. |
||||||
292 | * |
||||||
293 | * @param $object |
||||||
294 | * |
||||||
295 | * @return mixed |
||||||
296 | */ |
||||||
297 | protected function getElementContainer($object) |
||||||
298 | { |
||||||
299 | return $object->getContent(); |
||||||
300 | } |
||||||
301 | } |
||||||
302 |
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.