setNewIndex() public method

If the position is "before" or "after", an index will be chosen which makes the given node the previous or next node of the given reference node. If the position "last" is specified, an index higher than any existing index will be chosen. If no free index is available between two nodes (for "before" and "after"), the whole index of the current node level will be renumbered.
public setNewIndex ( NodeData $node, integer $position, Neos\ContentRepository\Domain\Model\NodeInterface $referenceNode = null ) : void
$node Neos\ContentRepository\Domain\Model\NodeData The node to set the new index for
$position integer The position the new index should reflect, must be one of the POSITION_* constants
$referenceNode Neos\ContentRepository\Domain\Model\NodeInterface The reference node. Mandatory for POSITION_BEFORE and POSITION_AFTER
return void
示例#1
0
 /**
  * Moves this node into the given node
  *
  * @param NodeInterface $referenceNode
  * @param string $newName
  * @throws NodeConstraintException
  * @throws NodeException
  * @throws NodeExistsException
  * @api
  */
 public function moveInto(NodeInterface $referenceNode, $newName = null)
 {
     if ($referenceNode === $this || $referenceNode === $this->getParent()) {
         return;
     }
     if ($this->getPath() === '/') {
         throw new NodeException('The root node cannot be moved.', 1346769001);
     }
     if ($referenceNode !== $this->getParent() && $referenceNode->getNode($this->getName()) !== null) {
         throw new NodeExistsException('Node with path "' . $this->getName() . '" already exists.', 1292503470);
     }
     if (!$referenceNode->willChildNodeBeAutoCreated($this->getName()) && !$referenceNode->isNodeTypeAllowedAsChildNode($this->getNodeType())) {
         throw new NodeConstraintException('Cannot move ' . $this->__toString() . ' into ' . $referenceNode->__toString(), 1404648124);
     }
     $name = $newName !== null ? $newName : $this->getName();
     $this->emitBeforeNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
     $this->setPath(NodePaths::addNodePathSegment($referenceNode->getPath(), $name));
     $this->nodeDataRepository->persistEntities();
     $this->nodeDataRepository->setNewIndex($this->nodeData, NodeDataRepository::POSITION_LAST);
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitAfterNodeMove($this, $referenceNode, NodeDataRepository::POSITION_LAST);
     $this->emitNodeUpdated($this);
 }