[TASK] Create own response instance in controller actions
[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 class AboutController
32 {
33 /**
34 * ModuleTemplate object
35 *
36 * @var ModuleTemplate
37 */
38 protected $moduleTemplate;
39
40 /**
41 * @var ViewInterface
42 */
43 protected $view;
44
45 /**
46 * Main action: Show standard information
47 *
48 * @return ResponseInterface the HTML output
49 */
50 public function indexAction(): ResponseInterface
51 {
52 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
53 $this->initializeView('index');
54 $warnings = [];
55 // Hook for additional warnings
56 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] ?? [] as $className) {
57 $hookObj = GeneralUtility::makeInstance($className);
58 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
59 $hookObj->displayWarningMessages_postProcess($warnings);
60 }
61 }
62
63 $this->view->assignMultiple([
64 'copyrightYear' => TYPO3_copyright_year,
65 'donationUrl' => TYPO3_URL_DONATE,
66 'currentVersion' => TYPO3_version,
67 'loadedExtensions' => $this->getLoadedExtensions(),
68 'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
69 'warnings' => $warnings,
70 'modules' => $this->getModulesData()
71 ]);
72
73 $this->moduleTemplate->setContent($this->view->render());
74 return new HtmlResponse($this->moduleTemplate->renderContent());
75 }
76
77 /**
78 * Create array with data of all main modules (Web, File, ...)
79 * and its nested sub modules
80 *
81 * @return array
82 */
83 protected function getModulesData(): array
84 {
85 $loadedModules = GeneralUtility::makeInstance(ModuleLoader::class);
86 $loadedModules->observeWorkspaces = true;
87 $loadedModules->load($GLOBALS['TBE_MODULES']);
88 $mainModulesData = [];
89 foreach ($loadedModules->modules as $moduleName => $moduleInfo) {
90 $moduleLabels = $loadedModules->getLabelsForModule($moduleName);
91 $mainModuleData = [
92 'name' => $moduleName,
93 'label' => $moduleLabels['title']
94 ];
95 if (is_array($moduleInfo['sub']) && !empty($moduleInfo['sub'])) {
96 $mainModuleData['subModules'] = $this->getSubModuleData($loadedModules, $moduleName);
97 }
98 $mainModulesData[] = $mainModuleData;
99 }
100 return $mainModulesData;
101 }
102
103 /**
104 * Create array with data of all subModules of a specific main module
105 *
106 * @param ModuleLoader $loadedModules the module loader instance
107 * @param string $moduleName Name of the main module
108 * @return array
109 */
110 protected function getSubModuleData(ModuleLoader $loadedModules, $moduleName): array
111 {
112 $subModulesData = [];
113 foreach ($loadedModules->modules[$moduleName]['sub'] as $subModuleName => $subModuleInfo) {
114 $moduleLabels = $loadedModules->getLabelsForModule($moduleName . '_' . $subModuleName);
115 $subModuleData = [];
116 $subModuleData['name'] = $subModuleName;
117 $subModuleData['icon'] = $subModuleInfo['icon'];
118 $subModuleData['iconIdentifier'] = $subModuleInfo['iconIdentifier'];
119 $subModuleData['label'] = $moduleLabels['title'];
120 $subModuleData['shortDescription'] = $moduleLabels['shortdescription'];
121 $subModuleData['longDescription'] = $moduleLabels['description'];
122 $subModulesData[] = $subModuleData;
123 }
124 return $subModulesData;
125 }
126
127 /**
128 * Fetches a list of all active (loaded) extensions in the current system
129 *
130 * @return array
131 */
132 protected function getLoadedExtensions(): array
133 {
134 $extensions = [];
135 $packageManager = GeneralUtility::makeInstance(PackageManager::class);
136 foreach ($packageManager->getActivePackages() as $package) {
137 // Skip system extensions (= type: typo3-cms-framework)
138 if ($package->getValueFromComposerManifest('type') !== 'typo3-cms-extension') {
139 continue;
140 }
141 $extensions[] = [
142 'key' => $package->getPackageKey(),
143 'title' => $package->getPackageMetaData()->getDescription(),
144 'authors' => $package->getValueFromComposerManifest('authors')
145 ];
146 }
147 return $extensions;
148 }
149
150 /**
151 * Initializes the view by setting the templateName
152 *
153 * @param string $templateName
154 */
155 protected function initializeView(string $templateName)
156 {
157 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
158 $this->view->setTemplate($templateName);
159 $this->view->setTemplateRootPaths(['EXT:about/Resources/Private/Templates/About']);
160 $this->view->setPartialRootPaths(['EXT:about/Resources/Private/Partials']);
161 $this->view->setLayoutRootPaths(['EXT:about/Resources/Private/Layouts']);
162 }
163 }