Neos\ContentRepository\Domain\Model\Node::moveBefore PHP Method

moveBefore() public method

Moves this node before the given node
public moveBefore ( Neos\ContentRepository\Domain\Model\NodeInterface $referenceNode, string $newName = null )
$referenceNode Neos\ContentRepository\Domain\Model\NodeInterface
$newName string
    public function moveBefore(NodeInterface $referenceNode, $newName = null)
    {
        if ($referenceNode === $this) {
            return;
        }
        if ($this->getPath() === '/') {
            throw new NodeException('The root node cannot be moved.', 1285005924);
        }
        if ($referenceNode->getParent() !== $this->getParent() && $referenceNode->getParent()->getNode($this->getName()) !== null) {
            throw new NodeExistsException('Node with path "' . $this->getName() . '" already exists.', 1292503468);
        }
        if (!$referenceNode->getParent()->willChildNodeBeAutoCreated($this->getName()) && !$referenceNode->getParent()->isNodeTypeAllowedAsChildNode($this->getNodeType())) {
            throw new NodeConstraintException('Cannot move ' . $this->__toString() . ' before ' . $referenceNode->__toString(), 1400782413);
        }
        $name = $newName !== null ? $newName : $this->getName();
        $this->emitBeforeNodeMove($this, $referenceNode, NodeDataRepository::POSITION_BEFORE);
        if ($referenceNode->getParentPath() !== $this->getParentPath()) {
            $this->setPath(NodePaths::addNodePathSegment($referenceNode->getParentPath(), $name));
            $this->nodeDataRepository->persistEntities();
        } else {
            if (!$this->isNodeDataMatchingContext()) {
                $this->materializeNodeData();
            }
        }
        $this->nodeDataRepository->setNewIndex($this->nodeData, NodeDataRepository::POSITION_BEFORE, $referenceNode);
        $this->context->getFirstLevelNodeCache()->flush();
        $this->emitAfterNodeMove($this, $referenceNode, NodeDataRepository::POSITION_BEFORE);
        $this->emitNodeUpdated($this);
    }
Node