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