public copy ( Neos\ContentRepository\Domain\Model\NodeInterface $node, Neos\ContentRepository\Domain\Model\NodeInterface $targetNode, string $position, string $nodeName = null ) : Neos\ContentRepository\Domain\Model\NodeInterface | ||
$node | Neos\ContentRepository\Domain\Model\NodeInterface | the node to be copied |
$targetNode | Neos\ContentRepository\Domain\Model\NodeInterface | 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 | Neos\ContentRepository\Domain\Model\NodeInterface | The copied node |
public function copy(NodeInterface $node, NodeInterface $targetNode, $position, $nodeName = null)
{
if (!in_array($position, array('before', 'into', 'after'), true)) {
throw new NodeException('The position should be one of the following: "before", "into", "after".', 1346832303);
}
$nodeName = $this->nodeService->generateUniqueNodeName($this->getDesignatedParentNode($targetNode, $position)->getPath(), !empty($nodeName) ? $nodeName : null);
switch ($position) {
case 'before':
$copiedNode = $node->copyBefore($targetNode, $nodeName);
break;
case 'after':
$copiedNode = $node->copyAfter($targetNode, $nodeName);
break;
case 'into':
default:
$copiedNode = $node->copyInto($targetNode, $nodeName);
}
return $copiedNode;
}
/** * Copies the given node before, into or after the target node depending on the given position and renders it's content collection. * * @param Node $node The node to be copied * @param Node $targetNode The target node to be copied "to", see $position * @param string $position Where the node should be added in relation to $targetNode (allowed: before, into, after) * @param string $nodeName Optional node name (if empty random node name will be generated) * @param string $typoScriptPath The TypoScript path of the collection * @return void */ public function copyAndRenderAction(Node $node, Node $targetNode, $position, $typoScriptPath, $nodeName = null) { $copiedNode = $this->nodeOperations->copy($node, $targetNode, $position, $nodeName); $this->redirectToRenderNode($copiedNode, $typoScriptPath); }