TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
MoveElementController.php
Go to the documentation of this file.
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;
26 
31 {
35  public $sys_language = 0;
36 
40  public $page_id;
41 
45  public $table;
46 
50  public $R_URI;
51 
56 
60  public $moveUid;
61 
65  public $makeCopy;
66 
72  public $perms_clause;
73 
79  public $content;
80 
84  public function __construct()
85  {
86  parent::__construct();
87  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
88  $GLOBALS['SOBE'] = $this;
89  $this->init();
90  }
91 
97  public function init()
98  {
99  // Setting internal vars:
100  $this->sys_language = (int)GeneralUtility::_GP('sys_language');
101  $this->page_id = (int)GeneralUtility::_GP('uid');
102  $this->table = GeneralUtility::_GP('table');
103  $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
104  $this->input_moveUid = GeneralUtility::_GP('moveUid');
105  $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
106  $this->makeCopy = GeneralUtility::_GP('makeCopy');
107  // Select-pages where clause for read-access:
108  $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
109  }
110 
119  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
120  {
121  $this->main();
122 
123  $this->moduleTemplate->setContent($this->content);
124  $response->getBody()->write($this->moduleTemplate->renderContent());
125  return $response;
126  }
127 
133  public function main()
134  {
135  $lang = $this->getLanguageService();
136  if ($this->page_id) {
137  $assigns = [];
138  $backendUser = $this->getBackendUser();
139  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
140  // Get record for element:
141  $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
142  // Headerline: Icon, record title:
143  $assigns['table'] = $this->table;
144  $assigns['elRow'] = $elRow;
145  $assigns['recordTooltip'] = BackendUtility::getRecordToolTip($elRow, $this->table);
146  $assigns['recordTitle'] = BackendUtility::getRecordTitle($this->table, $elRow, true);
147  // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
148  $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy])) . ';';
149  $assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : '';
150  $assigns['makeCopyOnClick'] = $onClick;
151  // IF the table is "pages":
152  if ((string)$this->table == 'pages') {
153  // Get page record (if accessible):
154  $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
155  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
156  // Initialize the position map:
157  $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
158  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
159  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
160  if ($pageInfo['pid']) {
161  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
162  if (is_array($pidPageInfo)) {
163  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
164  $assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([
165  'uid' => (int)$pageInfo['pid'],
166  'moveUid' => $this->moveUid
167  ]);
168  } else {
169  $assigns['pages']['pidPageInfo'] = $pidPageInfo;
170  }
171  $assigns['pages']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
172  }
173  }
174  // Create the position tree:
175  $assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
176  }
177  }
178  // IF the table is "tt_content":
179  if ((string)$this->table == 'tt_content') {
180  // First, get the record:
181  $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
182  // ?
183  if (!$this->input_moveUid) {
184  $this->page_id = $tt_content_rec['pid'];
185  }
186  // Checking if the parent page is readable:
187  $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
188  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
189  // Initialize the position map:
190  $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
191  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
192  $posMap->cur_sys_language = $this->sys_language;
193  // Headerline for the parent page: Icon, record title:
194  $assigns['ttContent']['pageInfo'] = $pageInfo;
195  $assigns['ttContent']['recordTooltip'] = BackendUtility::getRecordToolTip($pageInfo, 'pages');
196  $assigns['ttContent']['recordTitle'] = BackendUtility::getRecordTitle('pages', $pageInfo, true);
197  // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
198  // SHARED page-TSconfig settings.
199  // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
200  $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
201  $colPosIds = [];
202  foreach ($colPosArray as $colPos) {
203  $colPosIds[] = $colPos[1];
204  }
205  // Removing duplicates, if any
206  $colPosList = implode(',', array_unique($colPosIds));
207  // Adding parent page-header and the content element columns from position-map:
208  $assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
209  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
210  if ($pageInfo['pid']) {
211  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
212  if (is_array($pidPageInfo)) {
213  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
214  $assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([
215  'uid' => (int)$pageInfo['pid'],
216  'moveUid' => $this->moveUid
217  ]);
218  } else {
219  $assigns['ttContent']['pidPageInfo'] = $pidPageInfo;
220  }
221  $assigns['ttContent']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
222  }
223  }
224  // Create the position tree (for pages):
225  $assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
226  }
227  }
228  // Rendering of the output via fluid
229  $view = GeneralUtility::makeInstance(StandaloneView::class);
230  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
231  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
232  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
233  'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html'
234  ));
235  $view->assignMultiple($assigns);
236  $this->content .= $view->render();
237  }
238  // Setting up the buttons and markers for docheader
239  $this->getButtons();
240  // Build the <body> for the module
241  $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
242  }
243 
247  protected function getButtons()
248  {
249  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
250  if ($this->page_id) {
251  if ((string)$this->table == 'pages') {
252  $cshButton = $buttonBar->makeHelpButton()
253  ->setModuleName('xMOD_csh_corebe')
254  ->setFieldName('move_el_pages');
255  $buttonBar->addButton($cshButton);
256  } elseif ((string)$this->table == 'tt_content') {
257  $cshButton = $buttonBar->makeHelpButton()
258  ->setModuleName('xMOD_csh_corebe')
259  ->setFieldName('move_el_cs');
260  $buttonBar->addButton($cshButton);
261  }
262 
263  if ($this->R_URI) {
264  $backButton = $buttonBar->makeLinkButton()
265  ->setHref($this->R_URI)
266  ->setTitle($this->getLanguageService()->getLL('goBack'))
267  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
268  'actions-view-go-back',
270  ));
271  $buttonBar->addButton($backButton);
272  }
273  }
274  }
275 
281  protected function getLanguageService()
282  {
283  return $GLOBALS['LANG'];
284  }
285 
291  protected function getBackendUser()
292  {
293  return $GLOBALS['BE_USER'];
294  }
295 }
static getRecordWSOL($table, $uid, $fields= '*', $where= '', $useDeleteClause=true, $unsetMovePointers=false)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getRecord($table, $uid, $fields= '*', $where= '', $useDeleteClause=true)
static linkThisScript(array $getParams=[])
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static getFileAbsFileName($filename, $_=null, $_2=null)
static callUserFunction($funcName, &$params, &$ref, $_= '', $errorMode=0)