Neos\Neos\Service\Controller\NodeController::copyAction PHP Method

copyAction() public method

We need to call persistAll() in order to return the nextUri. We can't persist only the nodes in NodeDataRepository because they might be connected to images / resources which need to be updated at the same time.
public copyAction ( Node $node, Node $targetNode, string $position, string $nodeName = null ) : void
$node Neos\ContentRepository\Domain\Model\Node The node to be copied
$targetNode Neos\ContentRepository\Domain\Model\Node The target node to be copied "to", see $position
$position string Where the node should be added in relation to $targetNode (allowed: before, into, after)
$nodeName string Optional node name (if empty random node name will be generated)
return void
    public function copyAction(Node $node, Node $targetNode, $position, $nodeName = null)
    {
        $copiedNode = $this->nodeOperations->copy($node, $targetNode, $position, $nodeName);
        if ($this->request->getHttpRequest()->isMethodSafe() === false) {
            $this->persistenceManager->persistAll();
        }
        $q = new FlowQuery(array($copiedNode));
        $closestDocumentNode = $q->closest('[instanceof Neos.Neos:Document]')->get(0);
        $requestData = array('nextUri' => $this->uriBuilder->reset()->setFormat('html')->setCreateAbsoluteUri(true)->uriFor('show', array('node' => $closestDocumentNode), 'Frontend\\Node', 'Neos.Neos'), 'newNodePath' => $copiedNode->getContextPath());
        if ($node->getNodeType()->isOfType('Neos.Neos:Document')) {
            $requestData['nodeUri'] = $this->uriBuilder->reset()->setFormat('html')->setCreateAbsoluteUri(true)->uriFor('show', array('node' => $copiedNode), 'Frontend\\Node', 'Neos.Neos');
        }
        $this->view->assign('value', array('data' => $requestData, 'success' => true));
    }