[TASK] Always use Icon API for Module Icons
[Packages/TYPO3.CMS.git] / typo3 / sysext / about / Classes / Controller / ModulesController.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 TYPO3\CMS\Backend\Module\ModuleLoader;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\View\BackendTemplateView;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
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 {
53 parent::__construct();
54 $this->languageService = $languageService ?: $GLOBALS['LANG'];
55 }
56
57 /**
58 * Set up the doc header properly here
59 *
60 * @param ViewInterface $view
61 */
62 protected function initializeView(ViewInterface $view)
63 {
64 /** @var BackendTemplateView $view */
65 parent::initializeView($view);
66 // Disable Path
67 $view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
68 }
69
70 /**
71 * Show general information and the installed modules
72 *
73 * @return void
74 */
75 public function indexAction()
76 {
77 $warnings = array();
78 $securityWarnings = '';
79 // Hook for additional warnings
80 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'])) {
81 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] as $classRef) {
82 $hookObj = GeneralUtility::getUserObj($classRef);
83 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
84 $hookObj->displayWarningMessages_postProcess($warnings);
85 }
86 }
87 }
88 if (!empty($warnings)) {
89 if (count($warnings) > 1) {
90 $securityWarnings = '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>';
91 } else {
92 $securityWarnings = '<p>' . implode('', $warnings) . '</p>';
93 }
94 unset($warnings);
95 }
96
97 $this->view->assignMultiple(
98 array(
99 'TYPO3Version' => TYPO3_version,
100 'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
101 'warningMessages' => $securityWarnings,
102 'warningTitle' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:warning.header'),
103 'modules' => $this->getModulesData()
104 )
105 );
106 }
107
108 /**
109 * Create array with data of all main modules (Web, File, ...)
110 * and its nested sub modules
111 *
112 * @return array
113 */
114 protected function getModulesData()
115 {
116 /** @var $loadedModules ModuleLoader */
117 $loadedModules = GeneralUtility::makeInstance(ModuleLoader::class);
118 $loadedModules->observeWorkspaces = true;
119 $loadedModules->load($GLOBALS['TBE_MODULES']);
120 $mainModulesData = array();
121 foreach ($loadedModules->modules as $moduleName => $moduleInfo) {
122 $mainModuleData = array();
123 $moduleKey = $moduleName . '_tab';
124 $mainModuleData['name'] = $moduleName;
125 $mainModuleData['label'] = $this->languageService->moduleLabels['tabs'][$moduleKey];
126 if (is_array($moduleInfo['sub']) && !empty($moduleInfo['sub'])) {
127 $mainModuleData['subModules'] = $this->getSubModuleData($moduleName, $moduleInfo['sub']);
128 }
129 $mainModulesData[] = $mainModuleData;
130 }
131 return $mainModulesData;
132 }
133
134 /**
135 * Create array with data of all subModules of a specific main module
136 *
137 * @param string $moduleName Name of the main module
138 * @param array $subModulesInfo Sub module information
139 * @return array
140 */
141 protected function getSubModuleData($moduleName, array $subModulesInfo = array())
142 {
143 $subModulesData = array();
144 foreach ($subModulesInfo as $subModuleName => $subModuleInfo) {
145 $subModuleKey = $moduleName . '_' . $subModuleName . '_tab';
146 $subModuleData = array();
147 $subModuleData['name'] = $subModuleName;
148 $subModuleData['icon'] = $subModuleInfo['icon'];
149 $subModuleData['iconIdentifier'] = $subModuleInfo['iconIdentifier'];
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 }