[!!!][TASK] Remove deprecated code from backend controllers
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContentElement / MoveElementController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\ContentElement;
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\AbstractModule;
20 use TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap;
21 use TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap;
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 rendering the move-element wizard display
28 */
29 class MoveElementController extends AbstractModule
30 {
31 /**
32 * @var int
33 */
34 public $sys_language = 0;
35
36 /**
37 * @var int
38 */
39 public $page_id;
40
41 /**
42 * @var string
43 */
44 public $table;
45
46 /**
47 * @var string
48 */
49 public $R_URI;
50
51 /**
52 * @var int
53 */
54 public $input_moveUid;
55
56 /**
57 * @var int
58 */
59 public $moveUid;
60
61 /**
62 * @var int
63 */
64 public $makeCopy;
65
66 /**
67 * Pages-select clause
68 *
69 * @var string
70 */
71 public $perms_clause;
72
73 /**
74 * Content for module accumulated here.
75 *
76 * @var string
77 */
78 public $content;
79
80 /**
81 * Constructor
82 */
83 public function __construct()
84 {
85 parent::__construct();
86 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
87 $GLOBALS['SOBE'] = $this;
88 $this->init();
89 }
90
91 /**
92 * Constructor, initializing internal variables.
93 *
94 * @return void
95 */
96 public function init()
97 {
98 // Setting internal vars:
99 $this->sys_language = (int)GeneralUtility::_GP('sys_language');
100 $this->page_id = (int)GeneralUtility::_GP('uid');
101 $this->table = GeneralUtility::_GP('table');
102 $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
103 $this->input_moveUid = GeneralUtility::_GP('moveUid');
104 $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
105 $this->makeCopy = GeneralUtility::_GP('makeCopy');
106 // Select-pages where clause for read-access:
107 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
108 $this->content = '<h1>' . $this->getLanguageService()->getLL('movingElement') . '</h1>';
109 }
110
111 /**
112 * Injects the request object for the current request or subrequest
113 * As this controller goes only through the main() method, it is rather simple for now
114 *
115 * @param ServerRequestInterface $request the current request
116 * @param ResponseInterface $response
117 * @return ResponseInterface the response with the content
118 */
119 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
120 {
121 $this->main();
122
123 $this->moduleTemplate->setContent($this->content);
124 $response->getBody()->write($this->moduleTemplate->renderContent());
125 return $response;
126 }
127
128 /**
129 * Creating the module output.
130 *
131 * @return void
132 */
133 public function main()
134 {
135 $lang = $this->getLanguageService();
136 if ($this->page_id) {
137 $backendUser = $this->getBackendUser();
138 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
139 // Get record for element:
140 $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
141 // Headerline: Icon, record title:
142 $headerLine = '<span ' . BackendUtility::getRecordToolTip($elRow, $this->table) . '>' . $this->moduleTemplate->getIconFactory()->getIconForRecord($this->table, $elRow, Icon::SIZE_SMALL)->render() . '</span>';
143 $headerLine .= BackendUtility::getRecordTitle($this->table, $elRow, true);
144 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
145 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(array('makeCopy' => !$this->makeCopy))) . ';';
146 $headerLine .= '<div><input type="hidden" name="makeCopy" value="0" />' . '<input type="checkbox" name="makeCopy" id="makeCopy" value="1"' . ($this->makeCopy ? ' checked="checked"' : '') . ' onclick="' . htmlspecialchars($onClick) . '" /> <label for="makeCopy" class="t3-label-valign-top">' . $lang->getLL('makeCopy', 1) . '</label></div>';
147 // Add the header-content to the module content:
148 $this->content .= '<div>' . $headerLine . '</div>';
149 // Reset variable to pick up the module content in:
150 $code = '';
151 // IF the table is "pages":
152 if ((string)$this->table == 'pages') {
153 // Get page record (if accessible):
154 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
155 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
156 // Initialize the position map:
157 $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
158 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
159 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
160 if ($pageInfo['pid']) {
161 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
162 if (is_array($pidPageInfo)) {
163 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
164 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('uid' => (int)$pageInfo['pid'], 'moveUid' => $this->moveUid))) . '">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '</a><br />';
165 } else {
166 $code .= $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '<br />';
167 }
168 }
169 }
170 // Create the position tree:
171 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
172 }
173 }
174 // IF the table is "tt_content":
175 if ((string)$this->table == 'tt_content') {
176 // First, get the record:
177 $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
178 // ?
179 if (!$this->input_moveUid) {
180 $this->page_id = $tt_content_rec['pid'];
181 }
182 // Checking if the parent page is readable:
183 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
184 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
185 // Initialize the position map:
186 $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
187 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
188 $posMap->cur_sys_language = $this->sys_language;
189 // Headerline for the parent page: Icon, record title:
190 $headerLine = '<span ' . BackendUtility::getRecordToolTip($pageInfo, 'pages') . '>'
191 . $this->moduleTemplate->getIconFactory()->getIconForRecord(
192 'pages',
193 $pageInfo,
194 Icon::SIZE_SMALL
195 )->render() . '</span>';
196 $headerLine .= BackendUtility::getRecordTitle('pages', $pageInfo, true);
197 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
198 // SHARED page-TSconfig settings.
199 // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
200 $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
201 $colPosIds = array();
202 foreach ($colPosArray as $colPos) {
203 $colPosIds[] = $colPos[1];
204 }
205 // Removing duplicates, if any
206 $colPosList = implode(',', array_unique($colPosIds));
207 // Adding parent page-header and the content element columns from position-map:
208 $code = $headerLine . '<br />';
209 $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
210 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
211 $code .= '<br /><br />';
212 if ($pageInfo['pid']) {
213 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
214 if (is_array($pidPageInfo)) {
215 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
216 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array(
217 'uid' => (int)$pageInfo['pid'],
218 'moveUid' => $this->moveUid
219 ))) . '">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '</a><br />';
220 } else {
221 $code .= $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '<br />';
222 }
223 }
224 }
225 // Create the position tree (for pages):
226 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
227 }
228 }
229 // Add the $code content as a new section to the module:
230 $this->content .= '<h2>' . $lang->getLL('selectPositionOfElement') . '</h2>';
231 $this->content .= '<div>' . $code . '</div>';
232 }
233 // Setting up the buttons and markers for docheader
234 $this->getButtons();
235 // Build the <body> for the module
236 $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
237 }
238
239 /**
240 * Create the panel of buttons for submitting the form or otherwise perform operations.
241 */
242 protected function getButtons()
243 {
244 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
245 if ($this->page_id) {
246 if ((string)$this->table == 'pages') {
247 $cshButton = $buttonBar->makeHelpButton()
248 ->setModuleName('xMOD_csh_corebe')
249 ->setFieldName('move_el_pages');
250 $buttonBar->addButton($cshButton);
251 } elseif ((string)$this->table == 'tt_content') {
252 $cshButton = $buttonBar->makeHelpButton()
253 ->setModuleName('xMOD_csh_corebe')
254 ->setFieldName('move_el_cs');
255 $buttonBar->addButton($cshButton);
256 }
257
258 if ($this->R_URI) {
259 $backButton = $buttonBar->makeLinkButton()
260 ->setHref($this->R_URI)
261 ->setTitle($this->getLanguageService()->getLL('goBack'))
262 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
263 'actions-view-go-back',
264 Icon::SIZE_SMALL
265 ));
266 $buttonBar->addButton($backButton);
267 }
268 }
269 }
270
271 /**
272 * Returns LanguageService
273 *
274 * @return \TYPO3\CMS\Lang\LanguageService
275 */
276 protected function getLanguageService()
277 {
278 return $GLOBALS['LANG'];
279 }
280
281 /**
282 * Returns the current BE user.
283 *
284 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
285 */
286 protected function getBackendUser()
287 {
288 return $GLOBALS['BE_USER'];
289 }
290 }