‪TYPO3CMS  ‪main
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;
28 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Core\Imaging\IconSize;
35 
41 #[AsController]
43 {
44  private int ‪$sys_language = 0;
45  private int ‪$page_id = 0;
46  private string ‪$R_URI = '';
47  private int ‪$moveUid = 0;
48  private int ‪$makeCopy = 0;
49  private string ‪$perms_clause = '';
50 
51  public function ‪__construct(
52  private readonly ‪IconFactory $iconFactory,
53  private readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
54  private readonly ‪UriBuilder $uriBuilder,
55  ) {}
56 
57  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
58  {
59  $view = $this->moduleTemplateFactory->create($request);
60  $parsedBody = $request->getParsedBody();
61  $queryParams = $request->getQueryParams();
62 
63  $this->sys_language = (int)($parsedBody['sys_language'] ?? $queryParams['sys_language'] ?? 0);
64  $this->page_id = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0);
65  $this->R_URI = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
66  $this->moveUid = (int)(($parsedBody['moveUid'] ?? $queryParams['moveUid'] ?? false) ?: ‪$this->page_id);
67  $this->makeCopy = (int)($parsedBody['makeCopy'] ?? $queryParams['makeCopy'] ?? 0);
68  // Select-pages where clause for read-access
69  $this->perms_clause = $this->‪getBackendUser()->getPagePermsClause(‪Permission::PAGE_SHOW);
70 
71  // Setting up the buttons and markers for docheader
72  $this->‪getButtons($view);
73  // Build the <body> for the module
74  $view->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:movingElement'));
75  $view->assignMultiple($this->‪getContentVariables($request));
76  return $view->renderResponse('ContentElement/MoveElement');
77  }
78 
79  private function ‪getContentVariables(ServerRequestInterface $request): array
80  {
81  $queryParams = $request->getQueryParams();
82  if (!$this->page_id) {
83  return [];
84  }
85  $assigns = [];
86  $backendUser = $this->‪getBackendUser();
87  // Get record for element:
88  $elRow = BackendUtility::getRecordWSOL('tt_content', $this->moveUid);
89  // Headerline: Icon, record title:
90  $assigns['record'] = $elRow;
91  $assigns['recordTooltip'] = BackendUtility::getRecordIconAltText($elRow, 'tt_content');
92  $assigns['recordTitle'] = BackendUtility::getRecordTitle('tt_content', $elRow, true);
93  // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
94  $assigns['makeCopyChecked'] = (bool)$this->makeCopy;
95  $assigns['makeCopyUrl'] = $this->uriBuilder->buildUriFromRoute(
96  'move_element',
97  [
98  'uid' => $queryParams['uid'] ?? 0,
99  'moveUid' => $queryParams['moveUid'] ?? 0,
100  'makeCopy' => !$this->makeCopy,
101  'returnUrl' => $queryParams['returnUrl'] ?? '',
102  ]
103  );
104  // Get page record (if accessible):
105  if ($this->moveUid === $this->page_id) {
106  $this->page_id = (int)$elRow['pid'];
107  }
108  $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
109  $assigns['pageInfo'] = $pageInfo;
110  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
111  // Initialize the content position map:
112  $contentPositionMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
113  $contentPositionMap->copyMode = $this->makeCopy ? 'copy' : 'move';
114  $contentPositionMap->moveUid = ‪$this->moveUid;
115  $contentPositionMap->cur_sys_language = ‪$this->sys_language;
116  $contentPositionMap->R_URI = ‪$this->R_URI;
117  // Headerline for the parent page: Icon, record title:
118  $assigns['ttContent']['recordTooltip'] = BackendUtility::getRecordIconAltText($pageInfo, 'pages');
119  $assigns['ttContent']['recordTitle'] = BackendUtility::getRecordTitle('pages', $pageInfo, true);
120  // Adding parent page-header and the content element columns from position-map:
121  $assigns['contentElementColumns'] = $contentPositionMap->printContentElementColumns($this->page_id);
122  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
123  if ($pageInfo['pid'] > 0) {
124  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
125  if (is_array($pidPageInfo)) {
126  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
127  $assigns['goUpUrl'] = $this->uriBuilder->buildUriFromRoute(
128  'move_element',
129  [
130  'uid' => (int)$pageInfo['pid'],
131  'moveUid' => $this->moveUid,
132  'makeCopy' => $this->makeCopy,
133  'returnUrl' => $queryParams['returnUrl'] ?? '',
134  ]
135  );
136  } else {
137  $assigns['pidPageInfo'] = $pidPageInfo;
138  }
139  $assigns['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
140  }
141  }
142  // Create the position tree (for pages) without insert lines:
143  $pagePositionMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
144  $pagePositionMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
145  $pagePositionMap->moveUid = ‪$this->moveUid;
146  $pagePositionMap->dontPrintPageInsertIcons = 1;
147  $assigns['positionTree'] = $pagePositionMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI, $request);
148  }
149  return $assigns;
150  }
151 
155  private function ‪getButtons(‪ModuleTemplate $view): void
156  {
157  $buttonBar = $view->‪getDocHeaderComponent()->getButtonBar();
158  if ($this->page_id) {
159  if ($this->R_URI) {
160  $backButton = $buttonBar->makeLinkButton()
161  ->setHref($this->R_URI)
162  ->setShowLabelText(true)
163  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:goBack'))
164  ->setIcon($this->iconFactory->getIcon('actions-view-go-back', IconSize::SMALL));
165  $buttonBar->addButton($backButton);
166  }
167  }
168  }
169 
171  {
172  return ‪$GLOBALS['LANG'];
173  }
174 
176  {
177  return ‪$GLOBALS['BE_USER'];
178  }
179 }
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$page_id
‪int $page_id
Definition: MoveElementController.php:45
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\__construct
‪__construct(private readonly IconFactory $iconFactory, private readonly ModuleTemplateFactory $moduleTemplateFactory, private readonly UriBuilder $uriBuilder,)
Definition: MoveElementController.php:51
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$makeCopy
‪int $makeCopy
Definition: MoveElementController.php:48
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$perms_clause
‪string $perms_clause
Definition: MoveElementController.php:49
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getContentVariables
‪getContentVariables(ServerRequestInterface $request)
Definition: MoveElementController.php:79
‪TYPO3\CMS\Backend\Controller\ContentElement
Definition: ElementHistoryController.php:18
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$sys_language
‪int $sys_language
Definition: MoveElementController.php:44
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getButtons
‪getButtons(ModuleTemplate $view)
Definition: MoveElementController.php:155
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getBackendUser
‪getBackendUser()
Definition: MoveElementController.php:175
‪TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap
Definition: ContentMovingPagePositionMap.php:32
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$moveUid
‪int $moveUid
Definition: MoveElementController.php:47
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\getLanguageService
‪getLanguageService()
Definition: MoveElementController.php:170
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap
Definition: PageMovingPagePositionMap.php:30
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\mainAction
‪mainAction(ServerRequestInterface $request)
Definition: MoveElementController.php:57
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController
Definition: MoveElementController.php:43
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Controller\ContentElement\MoveElementController\$R_URI
‪string $R_URI
Definition: MoveElementController.php:46