TYPO3 CMS  TYPO3_7-6
ModuleController.php
Go to the documentation of this file.
1 <?php
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 
18 
23 {
27  protected $moduleMenu;
28 
33 
38  public function __construct()
39  {
41  $this->moduleMenu = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Module\ModuleStorage::class);
42  $this->moduleMenuRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Domain\Repository\Module\BackendModuleRepository::class);
43  }
44 
52  public function createModuleMenu()
53  {
54  if (empty($this->moduleMenu->getEntries())) {
56  $moduleMenu = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\View\ModuleMenuView::class);
57  $rawData = $moduleMenu->getRawModuleData();
60  }
61  }
62 
70  protected function convertRawModuleDataToModuleMenuObject(array $rawModuleData)
71  {
72  foreach ($rawModuleData as $module) {
73  $entry = $this->createEntryFromRawData($module);
74  if (isset($module['subitems']) && !empty($module['subitems'])) {
75  foreach ($module['subitems'] as $subitem) {
76  $subEntry = $this->createEntryFromRawData($subitem);
77  $entry->addChild($subEntry);
78  }
79  }
80  $this->moduleMenu->attachEntry($entry);
81  }
82  }
83 
90  protected function createEntryFromRawData(array $module)
91  {
93  $entry = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Domain\Model\Module\BackendModule::class);
94  if (!empty($module['name']) && is_string($module['name'])) {
95  $entry->setName($module['name']);
96  }
97  if (!empty($module['title']) && is_string($module['title'])) {
98  $entry->setTitle($this->getLanguageService()->sL($module['title']));
99  }
100  if (!empty($module['onclick']) && is_string($module['onclick'])) {
101  $entry->setOnClick($module['onclick']);
102  }
103  if (!empty($module['link']) && is_string($module['link'])) {
104  $entry->setLink($module['link']);
105  }
106  if (empty($module['link']) && !empty($module['path']) && is_string($module['path'])) {
107  $entry->setLink($module['path']);
108  }
109  if (!empty($module['description']) && is_string($module['description'])) {
110  $entry->setDescription($module['description']);
111  }
112  if (!empty($module['icon']) && is_array($module['icon'])) {
113  $entry->setIcon($module['icon']);
114  }
115  if (!empty($module['navigationComponentId']) && is_string($module['navigationComponentId'])) {
116  $entry->setNavigationComponentId($module['navigationComponentId']);
117  }
118  return $entry;
119  }
120 
128  {
129  foreach ($GLOBALS['TBE_MODULES_EXT'] as $mainModule => $tbeModuleExt) {
130  list($main) = explode('_', $mainModule);
131  $mainEntry = $this->moduleMenuRepository->findByModuleName($main);
132  if ($mainEntry !== false) {
133  $subEntries = $mainEntry->getChildren();
134  if (!empty($subEntries)) {
135  $matchingSubEntry = $this->moduleMenuRepository->findByModuleName($mainModule);
136  if ($matchingSubEntry !== false) {
137  if (array_key_exists('MOD_MENU', $tbeModuleExt) && array_key_exists('function', $tbeModuleExt['MOD_MENU'])) {
138  foreach ($tbeModuleExt['MOD_MENU']['function'] as $subModule) {
139  $entry = $this->createEntryFromRawData($subModule);
140  $matchingSubEntry->addChild($entry);
141  }
142  }
143  }
144  }
145  }
146  }
147  }
148 
154  protected function getLanguageService()
155  {
156  return $GLOBALS['LANG'];
157  }
158 }
convertRawModuleDataToModuleMenuObject(array $rawModuleData)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']