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 TYPO3\CMS\Core\Localization\LanguageService; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @internal |
24
|
|
|
*/ |
25
|
|
|
class WidgetGroupInitializationService |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var WidgetGroupRegistry |
29
|
|
|
*/ |
30
|
|
|
private $widgetGroupRegistry; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var WidgetRegistry |
34
|
|
|
*/ |
35
|
|
|
private $widgetRegistry; |
36
|
|
|
|
37
|
|
|
public function __construct(WidgetGroupRegistry $widgetGroupRegistry, WidgetRegistry $widgetRegistry) |
38
|
|
|
{ |
39
|
|
|
$this->widgetGroupRegistry = $widgetGroupRegistry; |
40
|
|
|
$this->widgetRegistry = $widgetRegistry; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Define the different groups of widgets as shown in the modal when adding a widget to the current dashboard |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
public function buildWidgetGroupsConfiguration(): array |
49
|
|
|
{ |
50
|
|
|
$groupConfigurations = []; |
51
|
|
|
foreach ($this->widgetGroupRegistry->getWidgetGroups() as $widgetGroup) { |
52
|
|
|
$widgets = []; |
53
|
|
|
$widgetGroupIdentifier = $widgetGroup->getIdentifier(); |
54
|
|
|
|
55
|
|
|
$widgetsForGroup = $this->widgetRegistry->getAvailableWidgetsForWidgetGroup($widgetGroupIdentifier); |
56
|
|
|
foreach ($widgetsForGroup as $widgetConfiguration) { |
57
|
|
|
$widgets[$widgetConfiguration->getIdentifier()] = [ |
58
|
|
|
'iconIdentifier' => $widgetConfiguration->getIconIdentifier(), |
59
|
|
|
'title' => $this->getLanguageService()->sl($widgetConfiguration->getTitle()), |
60
|
|
|
'description' => $this->getLanguageService()->sl($widgetConfiguration->getDescription()), |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$groupConfigurations[$widgetGroupIdentifier] = [ |
65
|
|
|
'identifier' => $widgetGroupIdentifier, |
66
|
|
|
'title' => $widgetGroup->getTitle(), |
67
|
|
|
'widgets' => $widgets, |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $groupConfigurations; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function getLanguageService(): LanguageService |
75
|
|
|
{ |
76
|
|
|
return $GLOBALS['LANG']; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|