[TASK] Remove dummy files in typo3/classes/
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Module / ModuleController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Module;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Class with utility functions for module menu
32 *
33 * @author Susanne Moog <typo3@susannemoog.de>
34 */
35 class ModuleController {
36
37 /**
38 * @var \TYPO3\CMS\Backend\Module\ModuleStorage
39 */
40 protected $moduleMenu;
41
42 /**
43 * @var \TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository
44 */
45 protected $moduleMenuRepository;
46
47 /**
48 * Constructor
49 */
50 public function __construct() {
51 $this->moduleMenu = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleStorage');
52 $this->moduleMenuRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Domain\\Repository\\Module\\BackendModuleRepository');
53 }
54
55 /**
56 * This method creates the module menu if necessary
57 * afterwards you only need an instance of \TYPO3\CMS\Backend\Module\ModuleStorage
58 * to get the menu
59 *
60 * @return void
61 */
62 public function createModuleMenu() {
63 if (count($this->moduleMenu->getEntries()) === 0) {
64 /** @var $moduleMenu \TYPO3\CMS\Backend\View\ModuleMenuView */
65 $moduleMenu = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\ModuleMenuView');
66 $rawData = $moduleMenu->getRawModuleData();
67 $this->convertRawModuleDataToModuleMenuObject($rawData);
68 $this->createMenuEntriesForTbeModulesExt();
69 }
70 }
71
72 /**
73 * Creates the module menu object structure from the raw data array
74 *
75 * @param array $rawModuleData
76 * @see class.modulemenu.php getRawModuleData()
77 * @return void
78 */
79 protected function convertRawModuleDataToModuleMenuObject(array $rawModuleData) {
80 foreach ($rawModuleData as $module) {
81 $entry = $this->createEntryFromRawData($module);
82 if (isset($module['subitems']) && count($module['subitems']) > 0) {
83 foreach ($module['subitems'] as $subitem) {
84 $subEntry = $this->createEntryFromRawData($subitem);
85 $entry->addChild($subEntry);
86 }
87 }
88 $this->moduleMenu->attachEntry($entry);
89 }
90 }
91
92 /**
93 * Creates a menu entry object from an array
94 *
95 * @param array $module
96 * @return \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule
97 */
98 protected function createEntryFromRawData(array $module) {
99 /** @var $entry \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule */
100 $entry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Domain\\Model\\Module\\BackendModule');
101 if (!empty($module['name']) && is_string($module['name'])) {
102 $entry->setName($module['name']);
103 }
104 if (!empty($module['title']) && is_string($module['title'])) {
105 $entry->setTitle($GLOBALS['LANG']->sL($module['title']));
106 }
107 if (!empty($module['onclick']) && is_string($module['onclick'])) {
108 $entry->setOnClick($module['onclick']);
109 }
110 if (!empty($module['link']) && is_string($module['link'])) {
111 $entry->setLink($module['link']);
112 }
113 if (empty($module['link']) && !empty($module['path']) && is_string($module['path'])) {
114 $entry->setLink($module['path']);
115 }
116 if (!empty($module['description']) && is_string($module['description'])) {
117 $entry->setDescription($module['description']);
118 }
119 if (!empty($module['icon']) && is_array($module['icon'])) {
120 $entry->setIcon($module['icon']);
121 }
122 if (!empty($module['navigationComponentId']) && is_string($module['navigationComponentId'])) {
123 $entry->setNavigationComponentId($module['navigationComponentId']);
124 }
125 return $entry;
126 }
127
128 /**
129 * Creates the "third level" menu entries (submodules for the info module for
130 * example) from the TBE_MODULES_EXT array
131 *
132 * @return void
133 */
134 protected function createMenuEntriesForTbeModulesExt() {
135 foreach ($GLOBALS['TBE_MODULES_EXT'] as $mainModule => $tbeModuleExt) {
136 list($main) = explode('_', $mainModule);
137 $mainEntry = $this->moduleMenuRepository->findByModuleName($main);
138 if ($mainEntry !== FALSE) {
139 $subEntries = $mainEntry->getChildren();
140 if (count($subEntries) > 0) {
141 $matchingSubEntry = $this->moduleMenuRepository->findByModuleName($mainModule);
142 if ($matchingSubEntry !== FALSE) {
143 if (array_key_exists('MOD_MENU', $tbeModuleExt) && array_key_exists('function', $tbeModuleExt['MOD_MENU'])) {
144 foreach ($tbeModuleExt['MOD_MENU']['function'] as $subModule) {
145 $entry = $this->createEntryFromRawData($subModule);
146 $matchingSubEntry->addChild($entry);
147 }
148 }
149 }
150 }
151 }
152 }
153 }
154
155 }
156
157
158 ?>