Service/CategoryService.php
protected function sortChildTree(&$tree)
    {
        /** @var AbstractCategoryDocument $node */
        if (is_array($tree)) {
            uasort($tree, [$this, 'sortNodes']);
            foreach ($tree as $node) {
                $children = $node->getChildren();
                if ($children) {
                    $this->sortChildTree($children);
                    $node->setChildren($children);
                }
            }
        } else {
            $tree->uasort([$this, 'sortNodes']);
            $tree->rewind();
            foreach ($tree as $node) {
                $children = $node->getChildren();
                if ($children) {
                    $this->sortChildTree($children);
                    $node->setChildren($children);
                }
            }
        }
    }
protected function sortChildTree(&$tree)
    {
        /** @var AbstractCategoryDocument $node */
        if (is_array($tree)) {
            uasort($tree, [$this, 'sortNodes']);
            foreach ($tree as $node) {
                $children = $node->getChildren();
                if ($children) {
                    $this->sortChildTree($children);
                    $node->setChildren($children);
                }
            }
        } else {
            $tree->uasort([$this, 'sortNodes']);
            $tree->rewind();
            foreach ($tree as $node) {
                $children = $node->getChildren();
                if ($children) {
                    $this->sortChildTree($children);
                    $node->setChildren($children);
                }
            }
        }
    }
protected function sortChildTree ( & $ tree ) { /** @var AbstractCategoryDocument $node */ if ( is_array ( $ tree ) ) { uasort ( $ tree , [ $ this , 'sortNodes' ] ) ; foreach ( $ tree as $ node ) { $ children = $ node -> getChildren ( ) ; if ( $ children ) { $ this -> sortChildTree ( $ children ) ; $ node -> setChildren ( $ children ) ; } } } else { $ tree -> uasort ( [ $ this , 'sortNodes' ] ) ; $ tree -> rewind ( ) ; foreach ( $ tree as $ node ) { $ children = $ node -> getChildren ( ) ; if ( $ children ) { $ this -> sortChildTree ( $ children ) ; $ node -> setChildren ( $ children ) ; } } } }
Sorts category tree by sort field.

@param array|\ArrayIterator $tree
Sorts category tree by sort field .