1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package midgard.admin.asgard |
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Component display |
11
|
|
|
* |
12
|
|
|
* @package midgard.admin.asgard |
13
|
|
|
*/ |
14
|
|
|
class midgard_admin_asgard_handler_components extends midcom_baseclasses_components_handler |
15
|
|
|
{ |
16
|
|
|
use midgard_admin_asgard_handler; |
17
|
|
|
|
18
|
|
|
private $components = []; |
19
|
|
|
|
20
|
|
|
private $libraries = []; |
21
|
|
|
|
22
|
2 |
|
public function _on_initialize() |
23
|
|
|
{ |
24
|
2 |
|
$this->add_stylesheet(MIDCOM_STATIC_URL . '/midgard.admin.asgard/components.css'); |
25
|
2 |
|
} |
26
|
|
|
|
27
|
2 |
|
private function _load_component_data(midcom_core_manifest $manifest) : array |
28
|
|
|
{ |
29
|
|
|
$data = [ |
30
|
2 |
|
'name' => $manifest->name, |
31
|
2 |
|
'title' => $manifest->get_name_translated(), |
32
|
2 |
|
'icon' => midcom::get()->componentloader->get_component_icon($manifest->name), |
33
|
2 |
|
'description' => $manifest->description, |
34
|
2 |
|
'toolbar' => new midcom_helper_toolbar() |
35
|
|
|
]; |
36
|
|
|
|
37
|
2 |
|
$data['toolbar']->add_item([ |
38
|
2 |
|
MIDCOM_TOOLBAR_URL => $this->router->generate('components_configuration', ['component' => $manifest->name]), |
39
|
2 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
40
|
2 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'wrench', |
41
|
|
|
]); |
42
|
2 |
|
$data['toolbar']->add_help_item($manifest->name); |
43
|
|
|
|
44
|
2 |
|
return $data; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
private function _list_components() |
48
|
|
|
{ |
49
|
1 |
|
foreach (midcom::get()->componentloader->get_manifests() as $manifest) { |
50
|
1 |
|
$type = ($manifest->purecode) ? 'libraries' : 'components'; |
51
|
1 |
|
$this->$type[$manifest->name] = $this->_load_component_data($manifest); |
52
|
|
|
} |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Component list view |
57
|
|
|
*/ |
58
|
1 |
|
public function _handler_list(array &$data) |
59
|
|
|
{ |
60
|
1 |
|
$data['view_title'] = $this->_l10n->get('components'); |
61
|
|
|
|
62
|
1 |
|
$this->_list_components(); |
63
|
|
|
|
64
|
|
|
// Set the breadcrumb data |
65
|
1 |
|
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get($this->_component)); |
66
|
1 |
|
$this->add_breadcrumb($this->router->generate('components'), $this->_l10n->get('components')); |
67
|
1 |
|
return $this->get_response(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Shows the loaded components |
72
|
|
|
*/ |
73
|
1 |
|
public function _show_list(string $handler_id, array &$data) |
74
|
|
|
{ |
75
|
1 |
|
$this->_show_lists('components'); |
76
|
1 |
|
$this->_show_lists('libraries'); |
77
|
1 |
|
} |
78
|
|
|
|
79
|
1 |
|
private function _show_lists(string $type) |
80
|
|
|
{ |
81
|
1 |
|
$this->_request_data['list_type'] = $type; |
82
|
1 |
|
midcom_show_style('midgard_admin_asgard_components_header'); |
83
|
1 |
|
foreach ($this->$type as $component_data) { |
84
|
1 |
|
$this->_request_data['component_data'] = $component_data; |
85
|
1 |
|
midcom_show_style('midgard_admin_asgard_components_item'); |
86
|
|
|
} |
87
|
1 |
|
midcom_show_style('midgard_admin_asgard_components_footer'); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Component display |
92
|
|
|
*/ |
93
|
1 |
|
public function _handler_component(string $component, array &$data) |
94
|
|
|
{ |
95
|
1 |
|
$data['component'] = $component; |
96
|
1 |
|
if (!midcom::get()->componentloader->is_installed($component)) { |
97
|
|
|
throw new midcom_error_notfound("Component {$component} is not installed."); |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
$data['component_data'] = $this->_load_component_data(midcom::get()->componentloader->get_manifest($component)); |
|
|
|
|
101
|
|
|
|
102
|
1 |
|
$data['view_title'] = $data['component_data']['title']; |
103
|
|
|
|
104
|
1 |
|
$data['asgard_toolbar']->add_item([ |
105
|
1 |
|
MIDCOM_TOOLBAR_URL => $this->router->generate('components_configuration', ['component' => $component]), |
106
|
1 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
107
|
1 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'wrench', |
108
|
|
|
]); |
109
|
|
|
|
110
|
|
|
// Set the breadcrumb data |
111
|
1 |
|
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get($this->_component)); |
112
|
1 |
|
$this->add_breadcrumb($this->router->generate('components'), $this->_l10n->get('components')); |
113
|
1 |
|
$this->add_breadcrumb('', $data['component_data']['title']); |
114
|
1 |
|
return $this->get_response('midgard_admin_asgard_components_component'); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|