‪TYPO3CMS  9.5
MoveElementController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
32 
38 {
40 
46  protected ‪$deprecatedPublicProperties = [
47  'sys_language' => 'Using $sys_language of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
48  'page_id' => 'Using $page_id of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
49  'table' => 'Using $table of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
50  'R_URI' => 'Using $R_URI of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
51  'input_moveUid' => 'Using $input_moveUid of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
52  'moveUid' => 'Using $moveUid of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
53  'makeCopy' => 'Using $makeCopy of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
54  'perms_clause' => 'Using $perms_clause of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
55  'content' => 'Using $content of MoveElementController from the outside is discouraged, as this variable is used for internal storage.',
56  ];
57 
61  protected ‪$sys_language = 0;
62 
66  protected ‪$page_id;
67 
71  protected ‪$table;
72 
76  protected ‪$R_URI;
77 
81  protected ‪$input_moveUid;
82 
86  protected ‪$moveUid;
87 
91  protected ‪$makeCopy;
92 
98  protected ‪$perms_clause;
99 
105  protected ‪$content;
106 
112  protected ‪$moduleTemplate;
113 
117  public function ‪__construct()
118  {
119  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
120  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
121 
122  // @deprecated since TYPO3 v9, will be obsolete in TYPO3 v10.0 with removal of init()
123  $request = ‪$GLOBALS['TYPO3_REQUEST'];
124  // @deprecated since TYPO3 v9, will be moved out of __construct() in TYPO3 v10.0
125  $this->‪init($request);
126  }
127 
135  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
136  {
137  $this->‪renderContent();
138 
139  return new ‪HtmlResponse($this->content);
140  }
141 
147  public function ‪init(ServerRequestInterface $request = null)
148  {
149  if ($request === null) {
150  // Method signature in TYPO3 v10.0: protected function init(ServerRequestInterface $request)
151  trigger_error('MoveElementController->init() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
152  $request = ‪$GLOBALS['TYPO3_REQUEST'];
153  }
154 
155  $parsedBody = $request->getParsedBody();
156  $queryParams = $request->getQueryParams();
157 
158  // Setting internal vars:
159  $this->sys_language = (int)($parsedBody['sys_language'] ?? $queryParams['sys_language'] ?? 0);
160  $this->page_id = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0);
161  $this->table = $parsedBody['table'] ?? $queryParams['table'] ?? null;
162  $this->R_URI = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
163  $this->input_moveUid = $parsedBody['moveUid'] ?? $queryParams['moveUid'] ?? null;
164  $this->moveUid = $this->input_moveUid ? $this->input_moveUid : ‪$this->page_id;
165  $this->makeCopy = $parsedBody['makeCopy'] ?? $queryParams['makeCopy'] ?? 0;
166  // Select-pages where clause for read-access:
167  $this->perms_clause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
168  }
169 
173  protected function ‪renderContent(): void
174  {
175  $lang = $this->‪getLanguageService();
176 
177  if ($this->page_id) {
178  $assigns = [];
179  $backendUser = $this->‪getBackendUser();
180  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
181  // Get record for element:
182  $elRow = ‪BackendUtility::getRecordWSOL($this->table, $this->moveUid);
183  // Headerline: Icon, record title:
184  $assigns['table'] = ‪$this->table;
185  $assigns['elRow'] = $elRow;
186  $assigns['recordTooltip'] = ‪BackendUtility::getRecordToolTip($elRow, $this->table);
187  $assigns['recordTitle'] = ‪BackendUtility::getRecordTitle($this->table, $elRow, true);
188  // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
189  $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy])) . ';';
190  $assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : '';
191  $assigns['makeCopyOnClick'] = $onClick;
192  // IF the table is "pages":
193  if ((string)$this->table === 'pages') {
194  // Get page record (if accessible):
195  $pageInfo = ‪BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
196  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
197  // Initialize the position map:
198  $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
199  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
200  $posMap->moveUid = ‪$this->moveUid;
201  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
202  if ($pageInfo['pid']) {
203  $pidPageInfo = ‪BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
204  if (is_array($pidPageInfo)) {
205  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
206  $assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([
207  'uid' => (int)$pageInfo['pid'],
208  'moveUid' => $this->moveUid
209  ]);
210  } else {
211  $assigns['pages']['pidPageInfo'] = $pidPageInfo;
212  }
213  $assigns['pages']['pidRecordTitle'] = ‪BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
214  }
215  }
216  // Create the position tree:
217  $assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
218  }
219  }
220  // IF the table is "tt_content":
221  if ((string)$this->table === 'tt_content') {
222  // First, get the record:
223  $tt_content_rec = ‪BackendUtility::getRecord('tt_content', $this->moveUid);
224  // ?
225  if (!$this->input_moveUid) {
226  $this->page_id = $tt_content_rec['pid'];
227  }
228  // Checking if the parent page is readable:
229  $pageInfo = ‪BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
230  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
231  // Initialize the position map:
232  $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
233  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
234  $posMap->moveUid = ‪$this->moveUid;
235  $posMap->cur_sys_language = ‪$this->sys_language;
236  // Headerline for the parent page: Icon, record title:
237  $assigns['ttContent']['pageInfo'] = $pageInfo;
238  $assigns['ttContent']['recordTooltip'] = ‪BackendUtility::getRecordToolTip($pageInfo, 'pages');
239  $assigns['ttContent']['recordTitle'] = ‪BackendUtility::getRecordTitle('pages', $pageInfo, true);
240  $colPosArray = GeneralUtility::callUserFunction(\‪TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
241  $colPosIds = [];
242  foreach ($colPosArray as $colPos) {
243  $colPosIds[] = $colPos[1];
244  }
245  // Removing duplicates, if any
246  $colPosList = implode(',', array_unique($colPosIds));
247  // Adding parent page-header and the content element columns from position-map:
248  $assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
249  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
250  if ($pageInfo['pid']) {
251  $pidPageInfo = ‪BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
252  if (is_array($pidPageInfo)) {
253  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
254  $assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([
255  'uid' => (int)$pageInfo['pid'],
256  'moveUid' => $this->moveUid
257  ]);
258  } else {
259  $assigns['ttContent']['pidPageInfo'] = $pidPageInfo;
260  }
261  $assigns['ttContent']['pidRecordTitle'] = ‪BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
262  }
263  }
264  // Create the position tree (for pages):
265  $assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
266  }
267  }
268  // Rendering of the output via fluid
269  $view = GeneralUtility::makeInstance(StandaloneView::class);
270  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
271  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
272  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
273  'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html'
274  ));
275  $view->assignMultiple($assigns);
276  $this->content .= $view->render();
277  }
278 
279  // Setting up the buttons and markers for docheader
280  $this->‪getButtons();
281  // Build the <body> for the module
282  $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
283  $this->moduleTemplate->setContent($this->content);
284 
285  $this->content = $this->moduleTemplate->renderContent();
286  }
287 
293  public function ‪main()
294  {
295  trigger_error('MoveElementController->main() will be replaced by protected method renderContent() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
296  $this->‪renderContent();
297  }
298 
302  protected function ‪getButtons()
303  {
304  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
305  if ($this->page_id) {
306  if ((string)$this->table === 'pages') {
307  $cshButton = $buttonBar->makeHelpButton()
308  ->setModuleName('xMOD_csh_corebe')
309  ->setFieldName('move_el_pages');
310  $buttonBar->addButton($cshButton);
311  } elseif ((string)$this->table === 'tt_content') {
312  $cshButton = $buttonBar->makeHelpButton()
313  ->setModuleName('xMOD_csh_corebe')
314  ->setFieldName('move_el_cs');
315  $buttonBar->addButton($cshButton);
316  }
317 
318  if ($this->R_URI) {
319  $backButton = $buttonBar->makeLinkButton()
320  ->setHref($this->R_URI)
321  ->setTitle($this->‪getLanguageService()->getLL('goBack'))
322  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
323  'actions-view-go-back',
325  ));
326  $buttonBar->addButton($backButton);
327  }
328  }
329  }
330 
334  protected function ‪getLanguageService(): ‪LanguageService
335  {
336  return ‪$GLOBALS['LANG'];
337  }
338 
342  protected function ‪getBackendUser(): ‪BackendUserAuthentication
343  {
344  return ‪$GLOBALS['BE_USER'];
345  }
346 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$page_id
‪int $page_id
Definition: MoveElementController.php:62
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\main
‪main()
Definition: MoveElementController.php:281
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$makeCopy
‪int $makeCopy
Definition: MoveElementController.php:82
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$perms_clause
‪string $perms_clause
Definition: MoveElementController.php:88
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:523
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\renderContent
‪renderContent()
Definition: MoveElementController.php:161
‪TYPO3\CMS\Backend\Controller\ContentElement
Definition: ElementHistoryController.php:2
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$sys_language
‪int $sys_language
Definition: MoveElementController.php:58
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$input_moveUid
‪int $input_moveUid
Definition: MoveElementController.php:74
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap
Definition: ContentMovingPagePositionMap.php:23
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$moveUid
‪int $moveUid
Definition: MoveElementController.php:78
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\__construct
‪__construct()
Definition: MoveElementController.php:105
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$table
‪string $table
Definition: MoveElementController.php:66
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordToolTip
‪static string getRecordToolTip(array $row, $table='pages')
Definition: BackendUtility.php:1603
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1811
‪TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap
Definition: PageMovingPagePositionMap.php:25
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: MoveElementController.php:123
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: MoveElementController.php:330
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: MoveElementController.php:100
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\init
‪init(ServerRequestInterface $request=null)
Definition: MoveElementController.php:135
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:174
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController
Definition: MoveElementController.php:38
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getLanguageService
‪LanguageService getLanguageService()
Definition: MoveElementController.php:322
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$R_URI
‪string $R_URI
Definition: MoveElementController.php:70
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getButtons
‪getButtons()
Definition: MoveElementController.php:290
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: MoveElementController.php:44
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array bool readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:635
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$content
‪string $content
Definition: MoveElementController.php:94