1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\Layout\View; |
4
|
|
|
|
5
|
|
|
use atk4\ui\Menu; |
6
|
|
|
use atk4\ui\Item; |
7
|
|
|
|
8
|
|
|
class ActionBar extends Menu |
9
|
|
|
{ |
10
|
|
|
public $ui = 'actionbar menu'; |
11
|
|
|
|
12
|
|
|
protected static $buttons = []; |
13
|
|
|
|
14
|
|
|
protected static $menus = []; |
15
|
|
|
|
16
|
|
|
protected static function getPredefined($key) |
17
|
|
|
{ |
18
|
|
|
$predefined = [ |
19
|
|
|
'back' => [ |
20
|
|
|
__('Back'), |
21
|
|
|
'icon' => 'arrow left', |
22
|
|
|
'weight' => 10000, |
23
|
|
|
'attr' => [ |
24
|
|
|
'href' => $_SERVER['HTTP_REFERER']?? 'javascript:window.history.back()' |
25
|
|
|
], |
26
|
|
|
], |
27
|
|
|
'save' => [ |
28
|
|
|
__('Save'), |
29
|
|
|
'icon' => 'save', |
30
|
|
|
], |
31
|
|
|
'add' => [ |
32
|
|
|
__('Add'), |
33
|
|
|
'icon' => 'add', |
34
|
|
|
], |
35
|
|
|
'edit' => [ |
36
|
|
|
__('Edit'), |
37
|
|
|
'icon' => 'edit' |
38
|
|
|
], |
39
|
|
|
'delete' => [ |
40
|
|
|
__('Delete'), |
41
|
|
|
'icon' => 'trash' |
42
|
|
|
], |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
return $predefined[$key] ?? ['label' => $key]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function renderView() |
49
|
|
|
{ |
50
|
|
|
$this->elements = collect($this->elements)->sortByDesc(function ($element) { |
51
|
|
|
return $element->weight ?? 10; |
52
|
|
|
})->toArray(); |
53
|
|
|
|
54
|
|
|
return parent::renderView(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Adds a button to the ActionBar |
59
|
|
|
* |
60
|
|
|
* @param string|array|ActionBarItem $button |
61
|
|
|
* |
62
|
|
|
* @return Item |
63
|
|
|
*/ |
64
|
|
|
public static function addItemButton($button, $defaults = []) |
65
|
|
|
{ |
66
|
|
|
$button = is_string($button)? self::getPredefined($button): $button; |
67
|
|
|
|
68
|
|
|
$button = is_array($button)? new ActionBarItem($button): $button; |
69
|
|
|
|
70
|
|
|
$actionBar = self::instance(); |
71
|
|
|
|
72
|
|
|
return $actionBar->addItem($actionBar->mergeSeeds($button, $defaults)); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public static function addButtons($buttons) |
76
|
|
|
{ |
77
|
|
|
foreach ((array) $buttons as $button) { |
78
|
|
|
self::addItemButton($button); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public static function addMenuButton($menu) |
83
|
|
|
{ |
84
|
|
|
return self::instance()->addMenu($menu); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public static function clear() |
88
|
|
|
{ |
89
|
|
|
self::instance()->elements = null; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return self |
94
|
|
|
*/ |
95
|
|
|
public static function instance() |
96
|
|
|
{ |
97
|
|
|
return ui()->layout->actionBar; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.