/** * Copies the source node directly as the first child of the destination * node and returns the created node. * * @param integer $nodeUid The node which will be duplicated. * @param integer $destinationUid The uid of the new node's parent. * @return integer The uid of the new node's first page. */ private function copyNodeToDestination($nodeUid, $destinationUid) { $beUserSave = $GLOBALS['BE_USER']; $GLOBALS['BE_USER']->uc['copyLevels'] = 100; $GLOBALS['BE_USER']->workspace = 0; $nodeData = new \stdClass(); $nodeData->serializeClassName = PagetreeNode::class; $nodeData->id = $nodeUid; $nodeData->type = 'pages'; /** @var PagetreeNode $node */ $node = GeneralUtility::makeInstance(PagetreeNode::class, (array) $nodeData); $duplicatedPageUid = Commands::copyNode($node, $destinationUid); $GLOBALS['BE_USER'] = $beUserSave; return $duplicatedPageUid; }
/** * Copies the source node directly after the destination node and returns the * created node. * * @param stdClass $nodeData * @param int $destination * @return array */ public function copyNodeAfterDestination($nodeData, $destination) { /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */ $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array) $nodeData); /** @var $dataProvider \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider */ $dataProvider = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\DataProvider::class); try { $newPageId = Commands::copyNode($node, -$destination); $newNode = Commands::getNode($newPageId); $newNode->setLeaf($node->isLeafNode()); $returnValue = $newNode->toArray(); } catch (\Exception $exception) { $returnValue = array('success' => false, 'message' => $exception->getMessage()); } return $returnValue; }
/** * Copies the source node directly after the destination node and returns the * created node. * * @param \stdClass $nodeData * @param int $destination * @return array */ public function copyNodeAfterDestination($nodeData, $destination) { /** @var $node PagetreeNode */ $node = GeneralUtility::makeInstance(PagetreeNode::class, (array) $nodeData); try { $newPageId = Commands::copyNode($node, -$destination); $newNode = Commands::getNode($newPageId); $newNode->setLeaf($node->isLeafNode()); $returnValue = $newNode->toArray(); } catch (\Exception $exception) { $returnValue = ['success' => false, 'message' => $exception->getMessage()]; } return $returnValue; }