Jackalope\Node::getOrderCommands PHP Method

getOrderCommands() public method

Returns the orderBefore commands to be applied to the childnodes to get from the original order to the new one
public getOrderCommands ( ) : array
return array of arrays with 2 fields: name of node to order before second name
    public function getOrderCommands()
    {
        if (!$this->originalNodesOrder) {
            return array();
        }
        $reorders = NodeHelper::calculateOrderBefore($this->originalNodesOrder, $this->nodes);
        $this->originalNodesOrder = null;
        return $reorders;
    }

Usage Example

 /**
  * {@inheritDoc}
  */
 public function reorderChildren(Node $node)
 {
     $reorders = $node->getOrderCommands();
     if (count($reorders) == 0) {
         // should not happen but safe is safe
         return;
     }
     $body = '';
     $path = $node->getPath();
     foreach ($reorders as $child => $destination) {
         if (is_null($destination)) {
             $body .= ">{$path}/{$child} : #last\r";
         } else {
             $body .= ">{$path}/{$child} : {$destination}#before\r";
         }
     }
     $this->setJsopBody(trim($body));
 }