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