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