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