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