‪TYPO3CMS  10.4
ServiceProvider.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 ArrayObject;
21 use Psr\Container\ContainerInterface;
25 use TYPO3\CMS\Core\Package\PackageManager;
27 
32 {
33 
37  protected static function ‪getPackagePath(): string
38  {
39  return __DIR__ . '/../';
40  }
41 
45  public function ‪getFactories(): array
46  {
47  return [
48  'dashboard.presets' => [ static::class, 'getDashboardPresets' ],
49  'dashboard.widgetGroups' => [ static::class, 'getWidgetGroups' ],
50  'dashboard.widgets' => [ static::class, 'getWidgets' ],
51  ];
52  }
53 
54  public function ‪getExtensions(): array
55  {
56  return [
57  DashboardPresetRegistry::class => [ static::class, 'configureDashboardPresetRegistry' ],
58  WidgetGroupRegistry::class => [ static::class, 'configureWidgetGroupRegistry' ],
59  'dashboard.presets' => [ static::class, 'configureDashboardPresets' ],
60  'dashboard.widgetGroups' => [ static::class, 'configureWidgetGroups' ],
61  'dashboard.widgets' => [ static::class, 'configureWidgets' ]
62  ] + parent::getExtensions();
63  }
64 
65  public static function ‪getDashboardPresets(ContainerInterface $container): ArrayObject
66  {
67  return new ArrayObject();
68  }
69 
70  public static function ‪getWidgetGroups(ContainerInterface $container): ArrayObject
71  {
72  return new ArrayObject();
73  }
74 
75  public static function ‪getWidgets(ContainerInterface $container): ArrayObject
76  {
77  return new ArrayObject();
78  }
79 
80  public static function ‪configureDashboardPresetRegistry(
81  ContainerInterface $container,
82  ‪DashboardPresetRegistry $dashboardPresetRegistry = null
84  $dashboardPresetRegistry = $dashboardPresetRegistry ?? ‪self::new($container, DashboardPresetRegistry::class);
85  $cache = $container->get('cache.core');
86 
87  $cacheIdentifier = 'Dashboard_' . sha1((string)(new ‪Typo3Version()) . ‪Environment::getProjectPath() . 'DashboardPresets');
88  if ($cache->has($cacheIdentifier)) {
89  $dashboardPresetsFromPackages = $cache->require($cacheIdentifier);
90  } else {
91  $dashboardPresetsFromPackages = $container->get('dashboard.presets')->getArrayCopy();
92  $cache->set($cacheIdentifier, 'return ' . var_export($dashboardPresetsFromPackages, true) . ';');
93  }
94 
95  foreach ($dashboardPresetsFromPackages as $identifier => $options) {
96  $preset = new ‪DashboardPreset(
97  $identifier,
98  $options['title'],
99  $options['description'],
100  $options['iconIdentifier'],
101  $options['defaultWidgets'],
102  $options['showInWizard']
103  );
104  $dashboardPresetRegistry->registerDashboardPreset($preset);
105  }
106 
107  return $dashboardPresetRegistry;
108  }
109 
110  public static function ‪configureWidgetGroupRegistry(
111  ContainerInterface $container,
112  ‪WidgetGroupRegistry $widgetGroupRegistry = null
114  $widgetGroupRegistry = $widgetGroupRegistry ?? ‪self::new($container, WidgetGroupRegistry::class);
115  $cache = $container->get('cache.core');
116 
117  $cacheIdentifier = 'Dashboard_' . sha1((string)(new ‪Typo3Version()) . ‪Environment::getProjectPath() . 'WidgetGroups');
118  if ($cache->has($cacheIdentifier)) {
119  $widgetGroupsFromPackages = $cache->require($cacheIdentifier);
120  } else {
121  $widgetGroupsFromPackages = $container->get('dashboard.widgetGroups')->getArrayCopy();
122  $cache->set($cacheIdentifier, 'return ' . var_export($widgetGroupsFromPackages, true) . ';');
123  }
124 
125  foreach ($widgetGroupsFromPackages as $identifier => $options) {
126  $group = new ‪WidgetGroup(
127  $identifier,
128  $options['title']
129  );
130  $widgetGroupRegistry->registerWidgetGroup($group);
131  }
132 
133  return $widgetGroupRegistry;
134  }
135 
141  public static function ‪configureDashboardPresets(ContainerInterface $container, ArrayObject $presets): ArrayObject
142  {
144 
145  foreach ($paths as $pathOfPackage) {
146  $dashboardPresetsFileNameForPackage = $pathOfPackage . 'Configuration/Backend/DashboardPresets.php';
147  if (file_exists($dashboardPresetsFileNameForPackage)) {
148  $definedPresetsInPackage = require $dashboardPresetsFileNameForPackage;
149  if (is_array($definedPresetsInPackage)) {
150  $presets->exchangeArray(array_merge($presets->getArrayCopy(), $definedPresetsInPackage));
151  }
152  }
153  }
154 
155  return $presets;
156  }
157 
164  public static function ‪configureWidgetGroups(ContainerInterface $container, ArrayObject $widgetGroups, string $path = null): ArrayObject
165  {
167 
168  foreach ($paths as $pathOfPackage) {
169  $widgetGroupsFileNameForPackage = $pathOfPackage . 'Configuration/Backend/DashboardWidgetGroups.php';
170  if (file_exists($widgetGroupsFileNameForPackage)) {
171  $definedGroupsInPackage = require $widgetGroupsFileNameForPackage;
172  if (is_array($definedGroupsInPackage)) {
173  $widgetGroups->exchangeArray(array_merge($widgetGroups->getArrayCopy(), $definedGroupsInPackage));
174  }
175  }
176  }
177  return $widgetGroups;
178  }
179 
186  public static function ‪configureWidgets(ContainerInterface $container, ArrayObject $widgets, string $path = null): ArrayObject
187  {
189 
190  foreach ($paths as $pathOfPackage) {
191  $widgetsFileNameForPackage = $pathOfPackage . 'Configuration/Backend/DashboardWidgets.php';
192  if (file_exists($widgetsFileNameForPackage)) {
193  $definedWidgetsInPackage = require $widgetsFileNameForPackage;
194  if (is_array($definedWidgetsInPackage)) {
195  $widgets->exchangeArray(array_merge($widgets->getArrayCopy(), $definedWidgetsInPackage));
196  }
197  }
198  }
199  return $widgets;
200  }
201 
202  protected static function ‪getPathsOfInstalledPackages(): array
203  {
204  $paths = [];
205  $packageManager = GeneralUtility::makeInstance(PackageManager::class);
206 
207  foreach ($packageManager->getActivePackages() as $package) {
208  $paths[] = $package->getPackagePath();
209  }
210 
211  return $paths;
212  }
213 }
‪TYPO3\CMS\Dashboard\DashboardPreset
Definition: DashboardPreset.php:26
‪TYPO3\CMS\Core\Package\AbstractServiceProvider
Definition: AbstractServiceProvider.php:31
‪TYPO3\CMS\Dashboard\WidgetGroupRegistry
Definition: WidgetGroupRegistry.php:26
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Dashboard\WidgetGroup
Definition: WidgetGroup.php:26
‪TYPO3\CMS\Dashboard\ServiceProvider\configureDashboardPresetRegistry
‪static configureDashboardPresetRegistry(ContainerInterface $container, DashboardPresetRegistry $dashboardPresetRegistry=null)
Definition: ServiceProvider.php:80
‪TYPO3\CMS\Core\Package\AbstractServiceProvider\new
‪static mixed new(ContainerInterface $container, string $className, array $constructorArguments=[])
Definition: AbstractServiceProvider.php:116
‪TYPO3\CMS\Dashboard\ServiceProvider\getWidgetGroups
‪static getWidgetGroups(ContainerInterface $container)
Definition: ServiceProvider.php:70
‪TYPO3\CMS\Dashboard\ServiceProvider\getExtensions
‪getExtensions()
Definition: ServiceProvider.php:54
‪TYPO3\CMS\Dashboard\ServiceProvider\getWidgets
‪static getWidgets(ContainerInterface $container)
Definition: ServiceProvider.php:75
‪TYPO3\CMS\Dashboard\ServiceProvider
Definition: ServiceProvider.php:32
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:169
‪TYPO3\CMS\Dashboard\ServiceProvider\getPathsOfInstalledPackages
‪static getPathsOfInstalledPackages()
Definition: ServiceProvider.php:202
‪TYPO3\CMS\Dashboard\ServiceProvider\getDashboardPresets
‪static getDashboardPresets(ContainerInterface $container)
Definition: ServiceProvider.php:65
‪TYPO3\CMS\Dashboard\ServiceProvider\configureWidgetGroupRegistry
‪static configureWidgetGroupRegistry(ContainerInterface $container, WidgetGroupRegistry $widgetGroupRegistry=null)
Definition: ServiceProvider.php:110
‪TYPO3\CMS\Dashboard\ServiceProvider\getFactories
‪getFactories()
Definition: ServiceProvider.php:45
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Dashboard\ServiceProvider\configureDashboardPresets
‪static ArrayObject configureDashboardPresets(ContainerInterface $container, ArrayObject $presets)
Definition: ServiceProvider.php:141
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Dashboard\ServiceProvider\configureWidgets
‪static ArrayObject configureWidgets(ContainerInterface $container, ArrayObject $widgets, string $path=null)
Definition: ServiceProvider.php:186
‪TYPO3\CMS\Dashboard
‪TYPO3\CMS\Dashboard\ServiceProvider\getPackagePath
‪static getPackagePath()
Definition: ServiceProvider.php:37
‪TYPO3\CMS\Dashboard\ServiceProvider\configureWidgetGroups
‪static ArrayObject configureWidgetGroups(ContainerInterface $container, ArrayObject $widgetGroups, string $path=null)
Definition: ServiceProvider.php:164
‪TYPO3\CMS\Dashboard\DashboardPresetRegistry
Definition: DashboardPresetRegistry.php:26