[TASK] Call explicit render() on icon objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / func / Classes / Controller / PageFunctionsController.php
1 <?php
2 namespace TYPO3\CMS\Func\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\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\CMS\Extbase\Object\ObjectManager;
24 use TYPO3\CMS\Fluid\View\StandaloneView;
25 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
26
27 /**
28 * Script Class for the Web > Functions module
29 * This class creates the framework to which other extensions can connect their sub-modules
30 */
31 class PageFunctionsController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
32
33 /**
34 * @var array
35 * @internal
36 */
37 public $pageinfo;
38
39 /**
40 * Document Template Object
41 *
42 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
43 */
44 public $doc;
45
46 /**
47 * The name of the module
48 *
49 * @var string
50 */
51 protected $moduleName = 'web_func';
52
53 /**
54 * @var IconFactory
55 */
56 protected $iconFactory;
57
58 /**
59 * Constructor
60 */
61 public function __construct() {
62 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_func.xlf');
64 $this->MCONF = array(
65 'name' => $this->moduleName,
66 );
67 }
68
69 /**
70 * Injects the request object for the current request or subrequest
71 * Then checks for module functions that have hooked in, and renders menu etc.
72 *
73 * @param ServerRequestInterface $request the current request
74 * @param ResponseInterface $response
75 * @return ResponseInterface the response with the content
76 */
77 public function mainAction(ServerRequestInterface $request, ResponseInterface $response) {
78 $GLOBALS['SOBE'] = $this;
79 $this->init();
80
81 // Checking for first level external objects
82 $this->checkExtObj();
83
84 // Checking second level external objects
85 $this->checkSubExtObj();
86 $this->main();
87
88 $response->getBody()->write($this->content);
89 return $response;
90 }
91
92 /**
93 * Initialize module header etc and call extObjContent function
94 *
95 * @return void
96 */
97 public function main() {
98 // Access check...
99 // The page will show only if there is a valid page and if this page may be viewed by the user
100 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
101 $access = is_array($this->pageinfo);
102 // Template markers
103 $markers = array(
104 'CSH' => '',
105 'FUNC_MENU' => '',
106 'CONTENT' => ''
107 );
108 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
109 $this->doc->setModuleTemplate('EXT:func/Resources/Private/Templates/func.html');
110 // Main
111 if ($this->id && $access) {
112 // JavaScript
113 $this->doc->postCode = $this->doc->wrapScriptTags('if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
114 // Setting up the context sensitive menu:
115 $this->doc->getContextMenuCode();
116 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('web_func')) . '" method="post"><input type="hidden" name="id" value="' . htmlspecialchars($this->id) . '" />';
117 $vContent = $this->doc->getVersionSelector($this->id, TRUE);
118 if ($vContent) {
119 $this->content .= $this->doc->section('', $vContent);
120 }
121 $this->extObjContent();
122 // Setting up the buttons and markers for docheader
123 $docHeaderButtons = $this->getButtons();
124 $markers['CSH'] = $docHeaderButtons['csh'];
125 $markers['FUNC_MENU'] = BackendUtility::getFuncMenu(
126 $this->id,
127 'SET[function]',
128 $this->MOD_SETTINGS['function'],
129 $this->MOD_MENU['function']
130 );
131 $markers['CONTENT'] = $this->content;
132 } else {
133 // If no access or if ID == zero
134 $title = $this->getLanguageService()->getLL('title');
135 $message = $this->getLanguageService()->getLL('clickAPage_content');
136 $view = GeneralUtility::makeInstance(StandaloneView::class);
137 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:func/Resources/Private/Templates/InfoBox.html'));
138 $view->assignMultiple(array(
139 'title' => $title,
140 'message' => $message,
141 'state' => InfoboxViewHelper::STATE_INFO
142 ));
143 $this->content = $view->render();
144
145 // Setting up the buttons and markers for docheader
146 $docHeaderButtons = $this->getButtons();
147 $markers['CSH'] = $docHeaderButtons['csh'];
148 $markers['CONTENT'] = $this->content;
149 }
150 // Build the <body> for the module
151 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
152 // Renders the module page
153 $this->content = $this->doc->render($this->getLanguageService()->getLL('title'), $this->content);
154 }
155
156 /**
157 * Print module content (from $this->content)
158 *
159 * @return void
160 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
161 */
162 public function printContent() {
163 GeneralUtility::logDeprecatedFunction();
164 echo $this->content;
165 }
166
167 /**
168 * Create the panel of buttons for submitting the form or otherwise perform operations.
169 *
170 * @return array All available buttons as an assoc. array
171 */
172 protected function getButtons() {
173 $buttons = array(
174 'csh' => '',
175 'view' => '',
176 'shortcut' => ''
177 );
178 // CSH
179 $buttons['csh'] = BackendUtility::cshItem('_MOD_web_func', '');
180 if ($this->id && is_array($this->pageinfo)) {
181 // View page
182 $buttons['view'] = '<a href="#" '
183 . 'onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" '
184 . 'title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
185 . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
186 // Shortcut
187 if ($this->getBackendUser()->mayMakeShortcut()) {
188 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->moduleName);
189 }
190 }
191 return $buttons;
192 }
193
194 /**
195 * Returns LanguageService
196 *
197 * @return \TYPO3\CMS\Lang\LanguageService
198 */
199 protected function getLanguageService() {
200 return $GLOBALS['LANG'];
201 }
202
203 /**
204 * Returns the current BE user.
205 *
206 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
207 */
208 protected function getBackendUser() {
209 return $GLOBALS['BE_USER'];
210 }
211
212
213 }