TYPO3  7.6
ExtdirectTreeCommands.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
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 
19 
24 {
31  public function visiblyNode($nodeData)
32  {
34  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
35  try {
36  Commands::visiblyNode($node);
37  $newNode = Commands::getNode($node->getId());
38  $newNode->setLeaf($node->isLeafNode());
39  $returnValue = $newNode->toArray();
40  } catch (\Exception $exception) {
41  $returnValue = array(
42  'success' => false,
43  'error' => $exception->getMessage()
44  );
45  }
46  return $returnValue;
47  }
48 
55  public function disableNode($nodeData)
56  {
58  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
59  try {
60  Commands::disableNode($node);
61  $newNode = Commands::getNode($node->getId());
62  $newNode->setLeaf($node->isLeafNode());
63  $returnValue = $newNode->toArray();
64  } catch (\Exception $exception) {
65  $returnValue = array(
66  'success' => false,
67  'message' => $exception->getMessage()
68  );
69  }
70  return $returnValue;
71  }
72 
79  public function deleteNode($nodeData)
80  {
82  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
83  try {
84  Commands::deleteNode($node);
85  $returnValue = array();
86  if ($GLOBALS['BE_USER']->workspace) {
87  $record = Commands::getNodeRecord($node->getId());
88  if ($record['_ORIG_uid']) {
89  $newNode = Commands::getNewNode($record);
90  $returnValue = $newNode->toArray();
91  }
92  }
93  } catch (\Exception $exception) {
94  $returnValue = array(
95  'success' => false,
96  'message' => $exception->getMessage()
97  );
98  }
99  return $returnValue;
100  }
101 
109  public function restoreNode($nodeData, $destination)
110  {
112  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
113  try {
114  Commands::restoreNode($node, $destination);
115  $newNode = Commands::getNode($node->getId());
116  $returnValue = $newNode->toArray();
117  } catch (\Exception $exception) {
118  $returnValue = array(
119  'success' => false,
120  'message' => $exception->getMessage()
121  );
122  }
123  return $returnValue;
124  }
125 
134  public function updateLabel($nodeData, $updatedLabel)
135  {
136  if ($updatedLabel === '') {
137  return array();
138  }
140  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
141  try {
142  Commands::updateNodeLabel($node, $updatedLabel);
143  $shortendedText = GeneralUtility::fixed_lgd_cs($updatedLabel, (int)$GLOBALS['BE_USER']->uc['titleLen']);
144  $returnValue = array(
145  'editableText' => $updatedLabel,
146  'updatedText' => htmlspecialchars($shortendedText)
147  );
148  } catch (\Exception $exception) {
149  $returnValue = array(
150  'success' => false,
151  'message' => $exception->getMessage()
152  );
153  }
154  return $returnValue;
155  }
156 
163  public static function setTemporaryMountPoint($nodeData)
164  {
166  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
167  $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'] = $node->getId();
168  $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
170  }
171 
179  public function moveNodeToFirstChildOfDestination($nodeData, $destination)
180  {
182  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
183  try {
184  Commands::moveNode($node, $destination);
185  $newNode = Commands::getNode($node->getId(), false);
186  $newNode->setLeaf($node->isLeafNode());
187  $returnValue = $newNode->toArray();
188  } catch (\Exception $exception) {
189  $returnValue = array(
190  'success' => false,
191  'message' => $exception->getMessage()
192  );
193  }
194  return $returnValue;
195  }
196 
204  public function moveNodeAfterDestination($nodeData, $destination)
205  {
207  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
208  try {
209  Commands::moveNode($node, -$destination);
210  $newNode = Commands::getNode($node->getId(), false);
211  $newNode->setLeaf($node->isLeafNode());
212  $returnValue = $newNode->toArray();
213  } catch (\Exception $exception) {
214  $returnValue = array(
215  'success' => false,
216  'message' => $exception->getMessage()
217  );
218  }
219  return $returnValue;
220  }
221 
230  public function copyNodeToFirstChildOfDestination($nodeData, $destination)
231  {
233  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
235  $dataProvider = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\DataProvider::class);
236  try {
237  $newPageId = Commands::copyNode($node, $destination);
238  $newNode = Commands::getNode($newPageId);
239  $newNode->setLeaf($node->isLeafNode());
240  $returnValue = $newNode->toArray();
241  } catch (\Exception $exception) {
242  $returnValue = array(
243  'success' => false,
244  'message' => $exception->getMessage()
245  );
246  }
247  return $returnValue;
248  }
249 
258  public function copyNodeAfterDestination($nodeData, $destination)
259  {
261  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
263  $dataProvider = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\DataProvider::class);
264  try {
265  $newPageId = Commands::copyNode($node, -$destination);
266  $newNode = Commands::getNode($newPageId);
267  $newNode->setLeaf($node->isLeafNode());
268  $returnValue = $newNode->toArray();
269  } catch (\Exception $exception) {
270  $returnValue = array(
271  'success' => false,
272  'message' => $exception->getMessage()
273  );
274  }
275  return $returnValue;
276  }
277 
285  public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType)
286  {
288  $parentNode = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$parentNodeData);
289  try {
290  $newPageId = Commands::createNode($parentNode, $parentNode->getId(), $pageType);
291  $returnValue = Commands::getNode($newPageId)->toArray();
292  } catch (\Exception $exception) {
293  $returnValue = array(
294  'success' => false,
295  'message' => $exception->getMessage()
296  );
297  }
298  return $returnValue;
299  }
300 
309  public function insertNodeAfterDestination($parentNodeData, $destination, $pageType)
310  {
312  $parentNode = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$parentNodeData);
313  try {
314  $newPageId = Commands::createNode($parentNode, -$destination, $pageType);
315  $returnValue = Commands::getNode($newPageId)->toArray();
316  } catch (\Exception $exception) {
317  $returnValue = array(
318  'success' => false,
319  'message' => $exception->getMessage()
320  );
321  }
322  return $returnValue;
323  }
324 
331  public static function getViewLink($nodeData)
332  {
334  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
335  $javascriptLink = BackendUtility::viewOnClick($node->getId());
336  $extractedLink = '';
337  if (preg_match('/window\\.open\\(\'([^\']+)\'/i', $javascriptLink, $match)) {
338  // Clean JSON-serialized ampersands ('&')
339  // @see GeneralUtility::quoteJSvalue()
340  $extractedLink = json_decode('"' . trim($match[1], '"') . '"', JSON_HEX_AMP);
341  };
342  return $extractedLink;
343  }
344 
355  public static function addRootlineOfNodeToStateHash($stateId, $nodeId)
356  {
357  $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
358  if (empty($mountPoints)) {
359  $mountPoints = array(0);
360  }
361  $mountPoints[] = (int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
362  $mountPoints = array_unique($mountPoints);
364  $userSettingsController = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Controller\UserSettingsController::class);
365  $state = $userSettingsController->process('get', 'BackendComponents.States.' . $stateId);
366  $state->stateHash = (object) $state->stateHash;
367  $rootline = BackendUtility::BEgetRootLine($nodeId, '', $GLOBALS['BE_USER']->workspace != 0);
368  $rootlineIds = array();
369  foreach ($rootline as $pageData) {
370  $rootlineIds[] = (int)$pageData['uid'];
371  }
372  foreach ($mountPoints as $mountPoint) {
373  if (!in_array($mountPoint, $rootlineIds, true)) {
374  continue;
375  }
376  $isFirstNode = true;
377  foreach ($rootline as $pageData) {
378  $node = Commands::getNewNode($pageData, $mountPoint);
379  if ($isFirstNode) {
380  $isFirstNode = false;
381  $state->stateHash->lastSelectedNode = $node->calculateNodeId();
382  } else {
383  $state->stateHash->{$node->calculateNodeId('')} = 1;
384  }
385  }
386  }
387  $userSettingsController->process('set', 'BackendComponents.States.' . $stateId, $state);
388  return (array)$state->stateHash;
389  }
390 }