‪TYPO3CMS  10.4
MoveElementController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
34 
40 {
44  protected ‪$sys_language = 0;
45 
49  protected ‪$page_id;
50 
54  protected ‪$table;
55 
59  protected ‪$R_URI;
60 
64  protected ‪$input_moveUid;
65 
69  protected ‪$moveUid;
70 
74  protected ‪$makeCopy;
75 
81  protected ‪$perms_clause;
82 
88  protected ‪$content;
89 
95  protected ‪$moduleTemplate;
96 
104  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
105  {
106  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
107  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
108  $this->‪init($request);
109  $this->‪renderContent();
110  return new ‪HtmlResponse($this->content);
111  }
112 
118  protected function ‪init(ServerRequestInterface $request)
119  {
120  $parsedBody = $request->getParsedBody();
121  $queryParams = $request->getQueryParams();
122 
123  // Setting internal vars:
124  $this->sys_language = (int)($parsedBody['sys_language'] ?? $queryParams['sys_language'] ?? 0);
125  $this->page_id = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0);
126  $this->table = $parsedBody['table'] ?? $queryParams['table'] ?? null;
127  $this->R_URI = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
128  $this->input_moveUid = $parsedBody['moveUid'] ?? $queryParams['moveUid'] ?? null;
129  $this->moveUid = $this->input_moveUid ?: ‪$this->page_id;
130  $this->makeCopy = $parsedBody['makeCopy'] ?? $queryParams['makeCopy'] ?? 0;
131  // Select-pages where clause for read-access:
132  $this->perms_clause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
133  }
134 
138  protected function ‪renderContent(): void
139  {
140  $lang = $this->‪getLanguageService();
141 
142  if ($this->page_id) {
143  $assigns = [];
144  $backendUser = $this->‪getBackendUser();
145  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
146  // Get record for element:
147  $elRow = ‪BackendUtility::getRecordWSOL($this->table, $this->moveUid);
148  // Headerline: Icon, record title:
149  $assigns['table'] = ‪$this->table;
150  $assigns['elRow'] = $elRow;
151  $assigns['recordTooltip'] = ‪BackendUtility::getRecordToolTip($elRow, $this->table);
152  $assigns['recordTitle'] = ‪BackendUtility::getRecordTitle($this->table, $elRow, true);
153  // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
154  $assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : '';
155  $assigns['makeCopyUrl'] = GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy]);
156  // IF the table is "pages":
157  if ((string)$this->table === 'pages') {
158  // Get page record (if accessible):
159  $pageInfo = ‪BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
160  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
161  // Initialize the position map:
162  $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
163  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
164  $posMap->moveUid = ‪$this->moveUid;
165  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
166  if ($pageInfo['pid']) {
167  $pidPageInfo = ‪BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
168  if (is_array($pidPageInfo)) {
169  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
170  $assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([
171  'uid' => (int)$pageInfo['pid'],
172  'moveUid' => $this->moveUid
173  ]);
174  } else {
175  $assigns['pages']['pidPageInfo'] = $pidPageInfo;
176  }
177  $assigns['pages']['pidRecordTitle'] = ‪BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
178  }
179  }
180  // Create the position tree:
181  $assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
182  }
183  }
184  // IF the table is "tt_content":
185  if ((string)$this->table === 'tt_content') {
186  // First, get the record:
187  $tt_content_rec = ‪BackendUtility::getRecord('tt_content', $this->moveUid);
188  // ?
189  if (!$this->input_moveUid) {
190  $this->page_id = $tt_content_rec['pid'];
191  }
192  // Checking if the parent page is readable:
193  $pageInfo = ‪BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
194  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
195  // Initialize the position map:
196  $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
197  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
198  $posMap->moveUid = ‪$this->moveUid;
199  $posMap->cur_sys_language = ‪$this->sys_language;
200  // Headerline for the parent page: Icon, record title:
201  $assigns['ttContent']['pageInfo'] = $pageInfo;
202  $assigns['ttContent']['recordTooltip'] = ‪BackendUtility::getRecordToolTip($pageInfo, 'pages');
203  $assigns['ttContent']['recordTitle'] = ‪BackendUtility::getRecordTitle('pages', $pageInfo, true);
204  $colPosArray = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
205  $colPosIds = [];
206  foreach ($colPosArray as $colPos) {
207  $colPosIds[] = $colPos[1];
208  }
209  // Removing duplicates, if any
210  $colPosList = implode(',', array_unique($colPosIds));
211  // Adding parent page-header and the content element columns from position-map:
212  $assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
213  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
214  if ($pageInfo['pid']) {
215  $pidPageInfo = ‪BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
216  if (is_array($pidPageInfo)) {
217  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
218  $assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([
219  'uid' => (int)$pageInfo['pid'],
220  'moveUid' => $this->moveUid
221  ]);
222  } else {
223  $assigns['ttContent']['pidPageInfo'] = $pidPageInfo;
224  }
225  $assigns['ttContent']['pidRecordTitle'] = ‪BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
226  }
227  }
228  // Create the position tree (for pages):
229  $assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
230  }
231  }
232  // Rendering of the output via fluid
233  $view = GeneralUtility::makeInstance(StandaloneView::class);
234  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
235  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
236  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
237  'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html'
238  ));
239  $view->assignMultiple($assigns);
240  $this->content .= $view->render();
241  }
242 
243  // Setting up the buttons and markers for docheader
244  $this->‪getButtons();
245  // Build the <body> for the module
246  $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
247  $this->moduleTemplate->setContent($this->content);
248 
249  $this->content = $this->moduleTemplate->renderContent();
250  }
251 
255  protected function ‪getButtons()
256  {
257  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
258  if ($this->page_id) {
259  if ((string)$this->table === 'pages') {
260  $cshButton = $buttonBar->makeHelpButton()
261  ->setModuleName('xMOD_csh_corebe')
262  ->setFieldName('move_el_pages');
263  $buttonBar->addButton($cshButton);
264  } elseif ((string)$this->table === 'tt_content') {
265  $cshButton = $buttonBar->makeHelpButton()
266  ->setModuleName('xMOD_csh_corebe')
267  ->setFieldName('move_el_cs');
268  $buttonBar->addButton($cshButton);
269  }
270 
271  if ($this->R_URI) {
272  $backButton = $buttonBar->makeLinkButton()
273  ->setHref($this->R_URI)
274  ->setTitle($this->‪getLanguageService()->getLL('goBack'))
275  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
276  'actions-view-go-back',
278  ));
279  $buttonBar->addButton($backButton);
280  }
281  }
282  }
283 
287  protected function ‪getLanguageService(): LanguageService
288  {
289  return ‪$GLOBALS['LANG'];
290  }
291 
295  protected function ‪getBackendUser(): BackendUserAuthentication
296  {
297  return ‪$GLOBALS['BE_USER'];
298  }
299 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$page_id
‪int $page_id
Definition: MoveElementController.php:47
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪array includeLLFile($fileRef, $setGlobal=null, $mergeLocalOntoDefault=null)
Definition: LanguageService.php:297
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$makeCopy
‪int $makeCopy
Definition: MoveElementController.php:67
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$perms_clause
‪string $perms_clause
Definition: MoveElementController.php:73
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:499
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\renderContent
‪renderContent()
Definition: MoveElementController.php:128
‪TYPO3\CMS\Backend\Controller\ContentElement
Definition: ElementHistoryController.php:16
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$sys_language
‪int $sys_language
Definition: MoveElementController.php:43
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$input_moveUid
‪int $input_moveUid
Definition: MoveElementController.php:59
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\init
‪init(ServerRequestInterface $request)
Definition: MoveElementController.php:108
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap
Definition: ContentMovingPagePositionMap.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$moveUid
‪int $moveUid
Definition: MoveElementController.php:63
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$table
‪string $table
Definition: MoveElementController.php:51
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordToolTip
‪static string getRecordToolTip(array $row, $table='pages')
Definition: BackendUtility.php:1339
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap
Definition: PageMovingPagePositionMap.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: MoveElementController.php:94
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: MoveElementController.php:285
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: MoveElementController.php:85
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array false readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:597
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Backend\View\BackendLayoutView
Definition: BackendLayoutView.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController
Definition: MoveElementController.php:40
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getLanguageService
‪LanguageService getLanguageService()
Definition: MoveElementController.php:277
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$R_URI
‪string $R_URI
Definition: MoveElementController.php:55
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getButtons
‪getButtons()
Definition: MoveElementController.php:245
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$content
‪string $content
Definition: MoveElementController.php:79