|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\PanelTraits; |
|
4
|
|
|
|
|
5
|
|
|
trait Tabs |
|
6
|
|
|
{ |
|
7
|
|
|
public $tabsEnabled = false; |
|
8
|
|
|
public $tabsType = 'horizontal'; |
|
9
|
|
|
|
|
10
|
|
|
public function enableTabs() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->tabsEnabled = true; |
|
13
|
|
|
$this->setTabsType(config('backpack.crud.tabs_type', 'horizontal')); |
|
14
|
|
|
|
|
15
|
|
|
return $this->tabsEnabled; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function disableTabs() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->tabsEnabled = false; |
|
21
|
|
|
|
|
22
|
|
|
return $this->tabsEnabled; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function tabsEnabled() |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
return $this->tabsEnabled; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function tabsDisabled() |
|
31
|
|
|
{ |
|
32
|
|
|
return ! $this->tabsEnabled; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function setTabsType($type) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$this->tabsType = $type; |
|
38
|
|
|
|
|
39
|
|
|
return $this->tabsType; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getTabsType() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
return $this->tabsType; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function enableVerticalTabs() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
return $this->setTabsType('vertical'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function disableVerticalTabs() |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
return $this->setTabsType('horizontal'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function enableHorizontalTabs() |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
return $this->setTabsType('horizontal'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function disableHorizontalTabs() |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
return $this->setTabsType('vertical'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function boxHasTabs($boxLabel) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->tabsEnabled() && count($this->getTabs($boxLabel)) > 0; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function tabExists($boxLabel, $tabLabel) |
|
73
|
|
|
{ |
|
74
|
|
|
$tabs = $this->getTabs($boxLabel); |
|
75
|
|
|
|
|
76
|
|
|
return in_array($tabLabel, $tabs); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getLastTab($boxLabel) |
|
80
|
|
|
{ |
|
81
|
|
|
$tabs = $this->getTabs($boxLabel); |
|
82
|
|
|
|
|
83
|
|
|
if (count($tabs)) { |
|
84
|
|
|
return last($tabs); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return false; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function isLastTab($boxLabel, $tabLabel) |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->getLastTab($boxLabel) == $tabLabel; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getTabFields($boxLabel, $tabLabel) |
|
96
|
|
|
{ |
|
97
|
|
|
if ($this->boxExists($boxLabel) && $this->tabExists($boxLabel, $tabLabel)) { |
|
|
|
|
|
|
98
|
|
|
$boxFields = $this->getBoxFields($boxLabel); |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
$fields_for_current_tab = collect($boxFields)->filter(function ($value, $key) use ($tabLabel) { |
|
|
|
|
|
|
101
|
|
|
return isset($value['tab']) && $value['tab'] == $tabLabel; |
|
102
|
|
|
}); |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
if ($this->isLastTab($boxLabel, $tabLabel)) { |
|
|
|
|
|
|
105
|
|
|
$fields_without_a_tab = collect($boxFields)->filter(function ($value, $key) { |
|
|
|
|
|
|
106
|
|
|
return ! isset($value['tab']); |
|
107
|
|
|
}); |
|
108
|
|
|
|
|
109
|
|
|
$fields_for_current_tab = $fields_for_current_tab->merge($fields_without_a_tab); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $fields_for_current_tab; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
return []; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function getTabs($boxLabel) |
|
119
|
|
|
{ |
|
120
|
|
|
$tabs = []; |
|
121
|
|
|
$fields = $this->getBoxFields($boxLabel); |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
$fields_with_tabs = collect($fields) |
|
|
|
|
|
|
124
|
|
|
->filter(function ($value, $key) { |
|
|
|
|
|
|
125
|
|
|
return isset($value['tab']); |
|
126
|
|
|
}) |
|
127
|
|
|
->each(function ($value, $key) use (&$tabs) { |
|
|
|
|
|
|
128
|
|
|
if (! in_array($value['tab'], $tabs)) { |
|
129
|
|
|
$tabs[] = $value['tab']; |
|
130
|
|
|
} |
|
131
|
|
|
}); |
|
132
|
|
|
|
|
133
|
|
|
return $tabs; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.