‪TYPO3CMS  10.4
WidgetRegistry.php
Go to the documentation of this file.
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;
26 
31 {
35  protected ‪$container;
36 
40  private ‪$widgets = [];
41 
45  private $widgetsPerWidgetGroup = [];
46 
47  public function __construct(ContainerInterface ‪$container)
48  {
49  $this->‪container = ‪$container;
50  }
51 
55  public function ‪getAvailableWidgets(): array
56  {
57  return $this->‪checkPermissionOfWidgets($this->widgets);
58  }
59 
63  public function ‪getAllWidgets(): array
64  {
65  return ‪$this->widgets;
66  }
67 
71  public function ‪getAvailableWidget(string $identifier): WidgetInterface
72  {
73  if (array_key_exists($identifier, $this->‪getAvailableWidgets())) {
74  return $this->‪container->get($this->widgets[$identifier]->getServiceName());
75  }
76 
77  throw new \InvalidArgumentException('Requested widget "' . $identifier . '" does not exist.', 1584777201);
78  }
79 
84  public function ‪getAvailableWidgetsForWidgetGroup(string $widgetGroupIdentifier): array
85  {
86  if (!array_key_exists($widgetGroupIdentifier, $this->widgetsPerWidgetGroup)) {
87  return [];
88  }
89  return $this->‪checkPermissionOfWidgets($this->widgetsPerWidgetGroup[$widgetGroupIdentifier]);
90  }
91 
92  public function ‪registerWidget(string $serviceName): void
93  {
94  $widgetConfiguration = $this->‪container->get($serviceName);
95  $this->widgets[$widgetConfiguration->getIdentifier()] = $widgetConfiguration;
96  foreach ($widgetConfiguration->getGroupNames() as $groupIdentifier) {
97  $this->widgetsPerWidgetGroup = ‪ArrayUtility::setValueByPath(
98  $this->widgetsPerWidgetGroup,
99  $groupIdentifier . '/' . $widgetConfiguration->getIdentifier(),
100  $widgetConfiguration
101  );
102  }
103  }
104 
109  protected function ‪checkPermissionOfWidgets(array ‪$widgets): array
110  {
111  return array_filter(‪$widgets, function ($identifier) {
112  return $this->‪getBackendUser()->check('available_widgets', $identifier);
113  }, ARRAY_FILTER_USE_KEY);
114  }
115 
116  public function ‪widgetItemsProcFunc(array &$parameters): void
117  {
118  foreach ($this->widgets as $widget) {
119  $parameters['items'][] = [
120  $widget->getTitle(),
121  $widget->getIdentifier(),
122  $widget->getIconIdentifier(),
123  null,
124  $widget->getDescription()
125  ];
126  }
127  }
128 
129  protected function ‪getBackendUser(): BackendUserAuthentication
130  {
131  return ‪$GLOBALS['BE_USER'];
132  }
133 }
‪TYPO3\CMS\Dashboard\WidgetRegistry\checkPermissionOfWidgets
‪WidgetConfigurationInterface[] checkPermissionOfWidgets(array $widgets)
Definition: WidgetRegistry.php:106
‪TYPO3\CMS\Dashboard\WidgetRegistry\$widgets
‪WidgetConfigurationInterface[] $widgets
Definition: WidgetRegistry.php:38
‪TYPO3\CMS\Dashboard\Widgets\WidgetInterface
Definition: WidgetInterface.php:26
‪TYPO3\CMS\Dashboard\WidgetRegistry\container
‪array< string, $widgetsPerWidgetGroup=array();public function __construct(ContainerInterface $container) { $this-> container
Definition: WidgetRegistry.php:46
‪TYPO3\CMS\Dashboard\WidgetRegistry\getBackendUser
‪getBackendUser()
Definition: WidgetRegistry.php:126
‪TYPO3\CMS\Dashboard\WidgetRegistry\registerWidget
‪registerWidget(string $serviceName)
Definition: WidgetRegistry.php:89
‪TYPO3\CMS\Dashboard\WidgetRegistry
Definition: WidgetRegistry.php:31
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Dashboard\WidgetRegistry\getAvailableWidgets
‪WidgetConfigurationInterface[] getAvailableWidgets()
Definition: WidgetRegistry.php:52
‪TYPO3\CMS\Dashboard\WidgetRegistry\getAvailableWidgetsForWidgetGroup
‪WidgetConfigurationInterface[] getAvailableWidgetsForWidgetGroup(string $widgetGroupIdentifier)
Definition: WidgetRegistry.php:81
‪TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath
‪static array setValueByPath(array $array, $path, $value, $delimiter='/')
Definition: ArrayUtility.php:272
‪TYPO3\CMS\Dashboard\WidgetRegistry\getAllWidgets
‪WidgetConfigurationInterface[] getAllWidgets()
Definition: WidgetRegistry.php:60
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Dashboard\WidgetRegistry\getAvailableWidget
‪getAvailableWidget(string $identifier)
Definition: WidgetRegistry.php:68
‪TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface
Definition: WidgetConfigurationInterface.php:26
‪TYPO3\CMS\Dashboard\WidgetRegistry\widgetItemsProcFunc
‪widgetItemsProcFunc(array &$parameters)
Definition: WidgetRegistry.php:113
‪TYPO3\CMS\Dashboard
‪TYPO3\CMS\Dashboard\WidgetRegistry\$container
‪ContainerInterface $container
Definition: WidgetRegistry.php:34