1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Dashboard; |
19
|
|
|
|
20
|
|
|
use Psr\Container\ContainerInterface; |
21
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
22
|
|
|
use TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface; |
23
|
|
|
use TYPO3\CMS\Dashboard\Widgets\WidgetInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @internal |
27
|
|
|
*/ |
28
|
|
|
class Dashboard |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $identifier; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $title; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $widgetConfig; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var WidgetRegistry |
47
|
|
|
*/ |
48
|
|
|
protected $widgetRegistry; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var ContainerInterface |
52
|
|
|
*/ |
53
|
|
|
protected $container; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var WidgetInterface[] |
57
|
|
|
*/ |
58
|
|
|
protected $widgets = []; |
59
|
|
|
|
60
|
|
|
public function __construct( |
61
|
|
|
string $identifier, |
62
|
|
|
string $title, |
63
|
|
|
array $widgetConfig, |
64
|
|
|
WidgetRegistry $widgetRegistry, |
65
|
|
|
ContainerInterface $container |
66
|
|
|
) { |
67
|
|
|
$this->identifier = $identifier; |
68
|
|
|
$this->title = $title; |
69
|
|
|
$this->widgetConfig = $widgetConfig; |
70
|
|
|
$this->widgetRegistry = $widgetRegistry; |
71
|
|
|
$this->container = $container; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getIdentifier(): string |
78
|
|
|
{ |
79
|
|
|
return $this->identifier; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getTitle(): string |
86
|
|
|
{ |
87
|
|
|
return $this->getLanguageService()->sl($this->title) ?: $this->title; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function getWidgetConfig(): array |
94
|
|
|
{ |
95
|
|
|
return $this->widgetConfig; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return WidgetInterface[] |
100
|
|
|
*/ |
101
|
|
|
public function getWidgets(): array |
102
|
|
|
{ |
103
|
|
|
return $this->widgets; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* This will return a list of all widgets of the current dashboard object. It will only include available |
108
|
|
|
* widgets and will add the initialized object of the widget itself |
109
|
|
|
*/ |
110
|
|
|
public function initializeWidgets(): void |
111
|
|
|
{ |
112
|
|
|
$availableWidgets = $this->widgetRegistry->getAvailableWidgets(); |
113
|
|
|
foreach ($this->widgetConfig as $hash => $widgetConfig) { |
114
|
|
|
/* @var WidgetConfigurationInterface $widgetConfig */ |
115
|
|
|
if (array_key_exists($widgetConfig['identifier'], $availableWidgets)) { |
116
|
|
|
$this->widgets[$hash] = $availableWidgets[$widgetConfig['identifier']]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return LanguageService |
123
|
|
|
*/ |
124
|
|
|
protected function getLanguageService(): LanguageService |
125
|
|
|
{ |
126
|
|
|
return $GLOBALS['LANG']; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|