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\Authentication\BackendUserAuthentication; |
22
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
23
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
24
|
|
|
use TYPO3\CMS\Dashboard\Widgets\WidgetInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @internal |
28
|
|
|
*/ |
29
|
|
|
class WidgetRegistry implements SingletonInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var ContainerInterface |
33
|
|
|
*/ |
34
|
|
|
protected $container; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var WidgetInterface[] |
38
|
|
|
*/ |
39
|
|
|
private $widgets = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private $widgetsPerWidgetGroup = []; |
45
|
|
|
|
46
|
|
|
public function __construct(ContainerInterface $container) |
47
|
|
|
{ |
48
|
|
|
$this->container = $container; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getAvailableWidgets(): array |
52
|
|
|
{ |
53
|
|
|
return $this->checkPermissionOfWidgets($this->widgets); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getAllWidgets(): array |
57
|
|
|
{ |
58
|
|
|
return $this->widgets; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws \InvalidArgumentException If requested identifier does not exist. |
63
|
|
|
*/ |
64
|
|
|
public function getAvailableWidget(string $identifier): WidgetInterface |
65
|
|
|
{ |
66
|
|
|
if (array_key_exists($identifier, $this->getAvailableWidgets())) { |
67
|
|
|
return $this->container->get($this->widgets[$identifier]->getServiceName()); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
throw new \InvalidArgumentException('Requested widget "' . $identifier . '" does not exist.', 1584777201); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getAvailableWidgetsForWidgetGroup(string $widgetGroupIdentifier): array |
74
|
|
|
{ |
75
|
|
|
if (!array_key_exists($widgetGroupIdentifier, $this->widgetsPerWidgetGroup)) { |
76
|
|
|
return []; |
77
|
|
|
} |
78
|
|
|
return $this->checkPermissionOfWidgets($this->widgetsPerWidgetGroup[$widgetGroupIdentifier]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function registerWidget(string $serviceName): void |
82
|
|
|
{ |
83
|
|
|
$widgetConfiguration = $this->container->get($serviceName); |
84
|
|
|
$this->widgets[$widgetConfiguration->getIdentifier()] = $widgetConfiguration; |
85
|
|
|
foreach ($widgetConfiguration->getGroupNames() as $groupIdentifier) { |
86
|
|
|
$this->widgetsPerWidgetGroup = ArrayUtility::setValueByPath( |
87
|
|
|
$this->widgetsPerWidgetGroup, |
88
|
|
|
$groupIdentifier . '/' . $widgetConfiguration->getIdentifier(), |
89
|
|
|
$widgetConfiguration |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function checkPermissionOfWidgets(array $widgets): array |
95
|
|
|
{ |
96
|
|
|
return array_filter($widgets, function ($identifier) { |
97
|
|
|
return $this->getBackendUser()->check('available_widgets', $identifier); |
98
|
|
|
}, ARRAY_FILTER_USE_KEY); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function widgetItemsProcFunc(array &$parameters): void |
102
|
|
|
{ |
103
|
|
|
foreach ($this->widgets as $widget) { |
104
|
|
|
$parameters['items'][] = [ |
105
|
|
|
$widget->getTitle(), |
|
|
|
|
106
|
|
|
$widget->getIdentifier(), |
|
|
|
|
107
|
|
|
$widget->getIconIdentifier() |
|
|
|
|
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
protected function getBackendUser(): BackendUserAuthentication |
113
|
|
|
{ |
114
|
|
|
return $GLOBALS['BE_USER']; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.