[TASK] In a ModuleController use iconFactory from moduleTemplate
[Packages/TYPO3.CMS.git] / typo3 / sysext / info / Classes / Controller / InfoModuleController.php
1 <?php
2 namespace TYPO3\CMS\Info\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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26 /**
27 * Script Class for the Web > Info module
28 * This class creates the framework to which other extensions can connect their sub-modules
29 */
30 class InfoModuleController extends BaseScriptClass
31 {
32 /**
33 * @var array
34 */
35 public $pageinfo;
36
37 /**
38 * Document Template Object
39 *
40 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
41 * @deprecated
42 */
43 public $doc;
44
45 /**
46 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
47 */
48 protected $backendUser;
49
50 /**
51 * @var \TYPO3\CMS\Lang\LanguageService
52 */
53 protected $languageService;
54
55 /**
56 * The name of the module
57 *
58 * @var string
59 */
60 protected $moduleName = 'web_info';
61
62 /**
63 * ModuleTemplate Container
64 *
65 * @var ModuleTemplate
66 */
67 protected $moduleTemplate;
68
69 /**
70 * Constructor
71 */
72 public function __construct()
73 {
74 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
75 $this->languageService = $GLOBALS['LANG'];
76 $this->languageService->includeLLFile('EXT:lang/locallang_mod_web_info.xlf');
77
78 $this->backendUser = $GLOBALS['BE_USER'];
79
80 $this->MCONF = array(
81 'name' => $this->moduleName,
82 );
83 }
84
85 /**
86 * Initialize module header etc and call extObjContent function
87 *
88 * @return void
89 */
90 public function main()
91 {
92 // We leave this here because of dependencies to submodules
93 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
94
95 // The page will show only if there is a valid page and if this page
96 // may be viewed by the user
97 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
98 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
99 $access = is_array($this->pageinfo);
100 if ($this->id && $access || $this->backendUser->user['admin'] && !$this->id) {
101 if ($this->backendUser->user['admin'] && !$this->id) {
102 $this->pageinfo = array('title' => '[root-level]', 'uid' => 0, 'pid' => 0);
103 }
104 // JavaScript
105 $this->moduleTemplate->addJavaScriptCode(
106 'WebFuncInLineJS',
107 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
108 function jumpToUrl(URL) {
109 window.location.href = URL;
110 return false;
111 }
112 '
113 );
114 // Setting up the context sensitive menu:
115 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
116 $this->moduleTemplate->setForm('<form action="' . htmlspecialchars(BackendUtility::getModuleUrl($this->moduleName)) .
117 '" method="post" name="webinfoForm" class="form-inline form-inline-spaced">');
118 $vContent = $this->moduleTemplate->getVersionSelector($this->id, 1);
119 if ($vContent) {
120 $this->content .= $this->moduleTemplate->section('', $vContent);
121 }
122 $this->extObjContent();
123 // Setting up the buttons and markers for docheader
124 $this->getButtons();
125 $this->generateMenu();
126 } else {
127 // If no access or if ID == zero
128 $this->content = $this->doc->header($this->languageService->getLL('title'));
129 }
130 }
131
132 /**
133 * Print module content (from $this->content)
134 *
135 * @return void
136 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
137 */
138 public function printContent()
139 {
140 GeneralUtility::logDeprecatedFunction();
141 $this->content = $this->doc->insertStylesAndJS($this->content);
142 echo $this->content;
143 }
144
145 /**
146 * Injects the request object for the current request or subrequest
147 * Then checks for module functions that have hooked in, and renders menu etc.
148 *
149 * @param ServerRequestInterface $request the current request
150 * @param ResponseInterface $response
151 * @return ResponseInterface the response with the content
152 */
153 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
154 {
155 $GLOBALS['SOBE'] = $this;
156 $this->init();
157
158 // Checking for first level external objects
159 $this->checkExtObj();
160
161 // Checking second level external objects
162 $this->checkSubExtObj();
163 $this->main();
164
165 $this->moduleTemplate->setContent($this->content);
166 $response->getBody()->write($this->moduleTemplate->renderContent());
167 return $response;
168 }
169
170 /**
171 * Create the panel of buttons for submitting the form or otherwise perform operations.
172 */
173 protected function getButtons()
174 {
175 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
176 // CSH
177 $cshButton = $buttonBar->makeHelpButton()
178 ->setModuleName('_MOD_web_info')
179 ->setFieldName('');
180 $buttonBar->addButton($cshButton, ButtonBar::BUTTON_POSITION_LEFT, 0);
181 // View page
182 $viewButton = $buttonBar->makeLinkButton()
183 ->setHref('#')
184 ->setOnClick(BackendUtility::viewOnClick(
185 $this->pageinfo['uid'],
186 '',
187 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
188 ))
189 ->setTitle($this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
190 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-view', Icon::SIZE_SMALL));
191 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
192 // Shortcut
193 $shortCutButton = $buttonBar->makeShortcutButton()
194 ->setModuleName($this->moduleName)
195 ->setGetVariables([
196 'M',
197 'id',
198 'edit_record',
199 'pointer',
200 'new_unique_uid',
201 'search_field',
202 'search_levels',
203 'showLimit'
204 ])
205 ->setSetVariables(array_keys($this->MOD_MENU));
206 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
207 }
208
209 /**
210 * Generate the ModuleMenu
211 */
212 protected function generateMenu()
213 {
214 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
215 $menu->setIdentifier('WebInfoJumpMenu');
216 foreach ($this->MOD_MENU['function'] as $controller => $title) {
217 $item = $menu
218 ->makeMenuItem()
219 ->setHref(
220 BackendUtility::getModuleUrl(
221 $this->moduleName,
222 [
223 'id' => $this->id,
224 'SET' => [
225 'function' => $controller
226 ]
227 ]
228 )
229 )
230 ->setTitle($title);
231 if ($controller === $this->MOD_SETTINGS['function']) {
232 $item->setActive(true);
233 }
234 $menu->addMenuItem($item);
235 }
236 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
237 }
238
239 /**
240 * Returns the ModuleTemplate container
241 * This is used by PageLayoutView.php
242 *
243 * @return ModuleTemplate
244 */
245 public function getModuleTemplate()
246 {
247 return $this->moduleTemplate;
248 }
249 }