[BUGFIX] Wrong margin calculation for Text/Image
[Packages/TYPO3.CMS.git] / typo3 / classes / Utility / BackendModuleUtility.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 - Susanne Moog <typo3@susannemoog.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Class with utility functions for module menu
30 *
31 * @author Susanne Moog <typo3@susannemoog.de>
32 * @package TYPO3
33 * @subpackage core
34 */
35 class Typo3_Utility_BackendModuleUtility {
36
37 /**
38 * @var Typo3_ModuleStorage
39 */
40 protected $moduleMenu;
41
42 /**
43 * @var Typo3_Repository_BackendModuleRepository
44 */
45 protected $moduleMenuRepository;
46
47 /**
48 * Constructor
49 */
50 public function __construct() {
51 $this->moduleMenu = t3lib_div::makeInstance('Typo3_ModuleStorage');
52 $this->moduleMenuRepository = t3lib_div::makeInstance('Typo3_Domain_Repository_BackendModuleRepository');
53 }
54
55 /**
56 * This method creates the module menu if necessary
57 * afterwards you only need an instance of Typo3_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 ModuleMenu */
65 $moduleMenu = t3lib_div::makeInstance('ModuleMenu');
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 * @see class.modulemenu.php getRawModuleData()
76 * @param array $rawModuleData
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_BackendModule
97 */
98 protected function createEntryFromRawData(array $module) {
99 /** @var $entry Typo3_BackendModule */
100 $entry = t3lib_div::makeInstance('Typo3_Domain_Model_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 example)
130 * 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 ?>