[BUGFIX] Fallback to empty array if ExportController receives no input
[Packages/TYPO3.CMS.git] / typo3 / sysext / about / Classes / Controller / AboutController.php
1 <?php
2 namespace TYPO3\CMS\About\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use TYPO3\CMS\Backend\Module\ModuleLoader;
19 use TYPO3\CMS\Backend\Template\ModuleTemplate;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Http\HtmlResponse;
22 use TYPO3\CMS\Core\Package\PackageManager;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Fluid\View\StandaloneView;
25 use TYPO3Fluid\Fluid\View\ViewInterface;
26
27 /**
28 * Module 'about' shows some standard information for TYPO3 CMS:
29 * About-text, version number, available modules and so on.
30 *
31 * @internal This is a specific Backend Controller implementation and is not considered part of the Public TYPO3 API.
32 */
33 class AboutController
34 {
35 /**
36 * ModuleTemplate object
37 *
38 * @var ModuleTemplate
39 */
40 protected $moduleTemplate;
41
42 /**
43 * @var ViewInterface
44 */
45 protected $view;
46
47 /**
48 * Main action: Show standard information
49 *
50 * @return ResponseInterface the HTML output
51 */
52 public function indexAction(): ResponseInterface
53 {
54 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
55 $this->initializeView('index');
56 $warnings = [];
57 // Hook for additional warnings
58 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] ?? [] as $className) {
59 $hookObj = GeneralUtility::makeInstance($className);
60 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
61 $hookObj->displayWarningMessages_postProcess($warnings);
62 }
63 }
64
65 $this->view->assignMultiple([
66 'copyrightYear' => TYPO3_copyright_year,
67 'donationUrl' => TYPO3_URL_DONATE,
68 'currentVersion' => TYPO3_version,
69 'loadedExtensions' => $this->getLoadedExtensions(),
70 'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
71 'warnings' => $warnings,
72 'modules' => $this->getModulesData()
73 ]);
74
75 $this->moduleTemplate->setContent($this->view->render());
76 return new HtmlResponse($this->moduleTemplate->renderContent());
77 }
78
79 /**
80 * Create array with data of all main modules (Web, File, ...)
81 * and its nested sub modules
82 *
83 * @return array
84 */
85 protected function getModulesData(): array
86 {
87 $loadedModules = GeneralUtility::makeInstance(ModuleLoader::class);
88 $loadedModules->observeWorkspaces = true;
89 $loadedModules->load($GLOBALS['TBE_MODULES']);
90 $mainModulesData = [];
91 foreach ($loadedModules->modules as $moduleName => $moduleInfo) {
92 $moduleLabels = $loadedModules->getLabelsForModule($moduleName);
93 $mainModuleData = [
94 'name' => $moduleName,
95 'label' => $moduleLabels['title']
96 ];
97 if (is_array($moduleInfo['sub']) && !empty($moduleInfo['sub'])) {
98 $mainModuleData['subModules'] = $this->getSubModuleData($loadedModules, $moduleName);
99 }
100 $mainModulesData[] = $mainModuleData;
101 }
102 return $mainModulesData;
103 }
104
105 /**
106 * Create array with data of all subModules of a specific main module
107 *
108 * @param ModuleLoader $loadedModules the module loader instance
109 * @param string $moduleName Name of the main module
110 * @return array
111 */
112 protected function getSubModuleData(ModuleLoader $loadedModules, $moduleName): array
113 {
114 if (empty($loadedModules->modules[$moduleName]['sub'])) {
115 return [];
116 }
117
118 $subModulesData = [];
119 foreach ($loadedModules->modules[$moduleName]['sub'] as $subModuleName => $subModuleInfo) {
120 $moduleLabels = $loadedModules->getLabelsForModule($moduleName . '_' . $subModuleName);
121 $subModuleData = [];
122 $subModuleData['name'] = $subModuleName;
123 $subModuleData['icon'] = $subModuleInfo['icon'] ?? null;
124 $subModuleData['iconIdentifier'] = $subModuleInfo['iconIdentifier'] ?? null;
125 $subModuleData['label'] = $moduleLabels['title'] ?? null;
126 $subModuleData['shortDescription'] = $moduleLabels['shortdescription'] ?? null;
127 $subModuleData['longDescription'] = $moduleLabels['description'] ?? null;
128 $subModulesData[] = $subModuleData;
129 }
130 return $subModulesData;
131 }
132
133 /**
134 * Fetches a list of all active (loaded) extensions in the current system
135 *
136 * @return array
137 */
138 protected function getLoadedExtensions(): array
139 {
140 $extensions = [];
141 $packageManager = GeneralUtility::makeInstance(PackageManager::class);
142 foreach ($packageManager->getActivePackages() as $package) {
143 // Skip system extensions (= type: typo3-cms-framework)
144 if ($package->getValueFromComposerManifest('type') !== 'typo3-cms-extension') {
145 continue;
146 }
147 $extensions[] = [
148 'key' => $package->getPackageKey(),
149 'title' => $package->getPackageMetaData()->getDescription(),
150 'authors' => $package->getValueFromComposerManifest('authors')
151 ];
152 }
153 return $extensions;
154 }
155
156 /**
157 * Initializes the view by setting the templateName
158 *
159 * @param string $templateName
160 */
161 protected function initializeView(string $templateName)
162 {
163 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
164 $this->view->setTemplate($templateName);
165 $this->view->setTemplateRootPaths(['EXT:about/Resources/Private/Templates/About']);
166 $this->view->setPartialRootPaths(['EXT:about/Resources/Private/Partials']);
167 $this->view->setLayoutRootPaths(['EXT:about/Resources/Private/Layouts']);
168 }
169 }