Example #1
0
    /**
     * Moves child to specified position. Rearange other children accordingly.
     *
     * @param MenuItem $child Child to move.
     * @param numeric $position Position to move child to.
     */
    public function moveChildToPosition(MenuItem $child, $position)
    {
        $name = $child->getName();
        $order = array_keys($this->children);

        $oldPosition = array_search($name, $order);
        unset($order[$oldPosition]);

        $order = array_values($order);

        array_splice($order, $position, 0, $name);
        $this->reorderChildren($order);
    }