[CLEANUP] Replace count with empty in multiple extensions
[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 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
30 * @author Christian Kuhn <lolli@schwarzbu.ch>
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 * @param LanguageService $languageService Language Service to inject
43 */
44 public function __construct(LanguageService $languageService = NULL) {
45 $this->languageService = $languageService ?: $GLOBALS['LANG'];
46 }
47
48 /**
49 * Show general information and the installed modules
50 *
51 * @return void
52 */
53 public function indexAction() {
54 $warnings = array();
55 $contentWarnings = '';
56 // Hook for additional warnings
57 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'])) {
58 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] as $classRef) {
59 $hookObj = GeneralUtility::getUserObj($classRef);
60 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
61 $hookObj->displayWarningMessages_postProcess($warnings);
62 }
63 }
64 }
65 if (!empty($warnings)) {
66 if (count($warnings) > 1) {
67 $securityWarnings = '<ul><li>' . implode('</li><li>', $warnings) . '</li></ul>';
68 } else {
69 $securityWarnings = '<p>' . implode('', $warnings) . '</p>';
70 }
71 $securityMessage = GeneralUtility::makeInstance(
72 FlashMessage::class,
73 $securityWarnings,
74 $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:warning.header'),
75 FlashMessage::ERROR
76 );
77 $contentWarnings = '<div style="margin: 20px 0;">' . $securityMessage->render() . '</div>';
78 unset($warnings);
79 }
80
81 $this->view->assignMultiple(
82 array(
83 'TYPO3Version' => TYPO3_version,
84 'copyRightNotice' => BackendUtility::TYPO3_copyRightNotice(),
85 'warningMessages' => $contentWarnings,
86 'modules' => $this->getModulesData()
87 )
88 );
89 }
90
91 /**
92 * Create array with data of all main modules (Web, File, ...)
93 * and its nested sub modules
94 *
95 * @return array
96 */
97 protected function getModulesData() {
98 /** @var $loadedModules \TYPO3\CMS\Backend\Module\ModuleLoader */
99 $loadedModules = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleLoader::class);
100 $loadedModules->observeWorkspaces = TRUE;
101 $loadedModules->load($GLOBALS['TBE_MODULES']);
102 $mainModulesData = array();
103 foreach ($loadedModules->modules as $moduleName => $moduleInfo) {
104 $mainModuleData = array();
105 $moduleKey = $moduleName . '_tab';
106 $mainModuleData['name'] = $moduleName;
107 $mainModuleData['label'] = $this->languageService->moduleLabels['tabs'][$moduleKey];
108 if (is_array($moduleInfo['sub']) && !empty($moduleInfo['sub'])) {
109 $mainModuleData['subModules'] = $this->getSubModuleData($moduleName, $moduleInfo['sub']);
110 }
111 $mainModulesData[] = $mainModuleData;
112 }
113 return $mainModulesData;
114 }
115
116 /**
117 * Create array with data of all subModules of a specific main module
118 *
119 * @param string $moduleName Name of the main module
120 * @param array $subModulesInfo Sub module information
121 * @return array
122 */
123 protected function getSubModuleData($moduleName, array $subModulesInfo = array()) {
124 $subModulesData = array();
125 foreach ($subModulesInfo as $subModuleName => $subModuleInfo) {
126 $subModuleKey = $moduleName . '_' . $subModuleName . '_tab';
127 $subModuleData = array();
128 $subModuleData['name'] = $subModuleName;
129 $subModuleData['icon'] = PathUtility::stripPathSitePrefix($this->languageService->moduleLabels['tabs_images'][$subModuleKey]);
130 $subModuleData['label'] = $this->languageService->moduleLabels['tabs'][$subModuleKey];
131 $subModuleData['shortDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'label'];
132 $subModuleData['longDescription'] = $this->languageService->moduleLabels['labels'][$subModuleKey . 'descr'];
133 $subModulesData[] = $subModuleData;
134 }
135 return $subModulesData;
136 }
137
138 }