Neos\Neos\Service\NodeOperations::move PHP Метод

move() публичный Метод

Move $node before, into or after $targetNode
public move ( Neos\ContentRepository\Domain\Model\NodeInterface $node, Neos\ContentRepository\Domain\Model\NodeInterface $targetNode, string $position ) : Neos\ContentRepository\Domain\Model\NodeInterface
$node Neos\ContentRepository\Domain\Model\NodeInterface
$targetNode Neos\ContentRepository\Domain\Model\NodeInterface
$position string where the node should be added (allowed: before, into, after)
Результат Neos\ContentRepository\Domain\Model\NodeInterface The same node given as first argument
    public function move(NodeInterface $node, NodeInterface $targetNode, $position)
    {
        if (!in_array($position, array('before', 'into', 'after'), true)) {
            throw new NodeException('The position should be one of the following: "before", "into", "after".', 1296132542);
        }
        $designatedParentNode = $this->getDesignatedParentNode($targetNode, $position);
        // If we stay inside the same parent we basically just reorder, no rename needed or wanted.
        if ($designatedParentNode !== $node->getParent()) {
            $designatedNodePath = NodePaths::addNodePathSegment($designatedParentNode->getPath(), $node->getName());
            if ($this->nodeService->nodePathAvailableForNode($designatedNodePath, $node) === false) {
                $nodeName = $this->nodeService->generateUniqueNodeName($designatedParentNode->getPath(), $node->getName());
                if ($nodeName !== $node->getName()) {
                    // FIXME: This can be removed if $node->move* supports additionally changing the name of the node.
                    $node->setName($nodeName);
                }
            }
        }
        switch ($position) {
            case 'before':
                $node->moveBefore($targetNode);
                break;
            case 'into':
                $node->moveInto($targetNode);
                break;
            case 'after':
                $node->moveAfter($targetNode);
        }
        return $node;
    }

Usage Example

Пример #1
0
 /**
  * Move 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 moved
  * @param Node $targetNode The target node to be moved "to", see $position
  * @param string $position Where the node should be added in relation to $targetNode (allowed: before, into, after)
  * @param string $typoScriptPath The TypoScript path of the collection
  * @return void
  */
 public function moveAndRenderAction(Node $node, Node $targetNode, $position, $typoScriptPath)
 {
     $this->nodeOperations->move($node, $targetNode, $position);
     $this->redirectToRenderNode($node, $typoScriptPath);
 }