[TASK] Use ModuleTemplate API for EXT:aboutmodules
[Packages/TYPO3.CMS.git] / typo3 / sysext / aboutmodules / Classes / Controller / ModulesController.php
1 <?php
2 namespace TYPO3\CMS\Aboutmodules\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 TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\View\BackendTemplateView;
19 use TYPO3\CMS\Core\Messaging\FlashMessage;
20 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Utility\PathUtility;
23 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
24 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
25 use TYPO3\CMS\Lang\LanguageService;
26
27 /**
28 * 'About modules' script - the default start-up module.
29 * Will display the list of main- and sub-modules available to the user.
30 * Each module will be show with description and a link to the module.
31 */
32 class ModulesController extends ActionController {
33
34 /**
35 * Language Service property. Used to access localized labels
36 *
37 * @var LanguageService
38 */
39 protected $languageService;
40
41 /**
42 * BackendTemplateView Container
43 *
44 * @var BackendTemplateView
45 */
46 protected $defaultViewObjectName = BackendTemplateView::class;
47
48 /**
49 * @param LanguageService $languageService Language Service to inject
50 */
51 public function __construct(LanguageService $languageService = NULL) {
52 parent::__construct();
53 $this->languageService = $languageService ?: $GLOBALS['LANG'];
54 }
55
56 /**
57 * Set up the doc header properly here
58 *
59 * @param ViewInterface $view
60 */
61 protected function initializeView(ViewInterface $view) {
62 /** @var BackendTemplateView $view */
63 parent::initializeView($view);
64 // Disable Path
65 $view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
66 }
67
68 /**
69 * Show general information and the installed modules
70 *
71 * @return void
72 */
73 public function indexAction() {
74 $warnings = array();
75 $contentWarnings = '';
76 // Hook for additional warnings
77 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'])) {
78 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] as $classRef) {
79 $hookObj = GeneralUtility::getUserObj($classRef);
80 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
81 $hookObj->displayWarningMessages_postProcess($warnings);
82 }
83 }
84 }
85 if (!empty($warnings)) {
86 if (count($warnings) > 1) {
87 $securityWarnings = '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>';
88 } else {
89 $securityWarnings = '<p>' . implode('', $warnings) . '</p>';
90 }
91 $securityMessage = GeneralUtility::makeInstance(
92 FlashMessage::class,
93 $securityWarnings,
94 $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:warning.header'),
95 FlashMessage::ERROR
96 );
97 $contentWarnings = '<div style="margin: 20px 0;">' . $securityMessage->render() . '</div>';
98 unset($warnings);
99 }
100
101 $this->view->assignMultiple(
102 array(
103 'TYPO3Version' => TYPO3_version,
104 'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
105 'warningMessages' => $contentWarnings,
106 'modules' => $this->getModulesData()
107 )
108 );
109 }
110
111 /**
112 * Create array with data of all main modules (Web, File, ...)
113 * and its nested sub modules
114 *
115 * @return array
116 */
117 protected function getModulesData() {
118 /** @var $loadedModules \TYPO3\CMS\Backend\Module\ModuleLoader */
119 $loadedModules = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleLoader::class);
120 $loadedModules->observeWorkspaces = TRUE;
121 $loadedModules->load($GLOBALS['TBE_MODULES']);
122 $mainModulesData = array();
123 foreach ($loadedModules->modules as $moduleName => $moduleInfo) {
124 $mainModuleData = array();
125 $moduleKey = $moduleName . '_tab';
126 $mainModuleData['name'] = $moduleName;
127 $mainModuleData['label'] = $this->languageService->moduleLabels['tabs'][$moduleKey];
128 if (is_array($moduleInfo['sub']) && !empty($moduleInfo['sub'])) {
129 $mainModuleData['subModules'] = $this->getSubModuleData($moduleName, $moduleInfo['sub']);
130 }
131 $mainModulesData[] = $mainModuleData;
132 }
133 return $mainModulesData;
134 }
135
136 /**
137 * Create array with data of all subModules of a specific main module
138 *
139 * @param string $moduleName Name of the main module
140 * @param array $subModulesInfo Sub module information
141 * @return array
142 */
143 protected function getSubModuleData($moduleName, array $subModulesInfo = array()) {
144 $subModulesData = array();
145 foreach ($subModulesInfo as $subModuleName => $subModuleInfo) {
146 $subModuleKey = $moduleName . '_' . $subModuleName . '_tab';
147 $subModuleData = array();
148 $subModuleData['name'] = $subModuleName;
149 $subModuleData['icon'] = PathUtility::stripPathSitePrefix($this->languageService->moduleLabels['tabs_images'][$subModuleKey]);
150 $subModuleData['label'] = $this->languageService->moduleLabels['tabs'][$subModuleKey];
151 $subModuleData['shortDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'label'];
152 $subModuleData['longDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'descr'];
153 $subModulesData[] = $subModuleData;
154 }
155 return $subModulesData;
156 }
157
158 }