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