Tree icon indicating copy to clipboard operation
Tree copied to clipboard

How can I duplicate/propogate children structure of a node

Open akudryav opened this issue 3 years ago • 1 comments

Is it possible to duplicate child of a node with all its subchildren structure? Give example please.

akudryav avatar Mar 30 '22 06:03 akudryav

Depends on what you are trying to do. If you want to alter the tree, then there is no built-in support for this, as the library is aimed at read-only access to tree data.

However, nothing keeps you from doing something like this:

$nodeToBeCloned = $tree->getNodeById($idOfNodeToBeCloned);
$clone = clone $nodeToBeCloned;
$nodeToBeCloned->getParent()->addChild($clone);

(And by the way: sorry for the late answer. Chances are that you don’t need it anymore …)

BlueM avatar Oct 03 '24 16:10 BlueM