/** * {@inheritdoc} **/ public function setChildNodeOf(NodeInterface $node) { $id = $this->getId(); if (empty($id)) { throw new \LogicException('You must provide an id for this node if you want it to be part of a tree.'); } $path = rtrim($node->getRealMaterializedPath(), static::getMaterializedPathSeparator()); $this->setMaterializedPath($path); if (null !== $this->parentNode) { $this->parentNode->getChildNodes()->removeElement($this); } $this->parentNode = $node; $this->parentNode->addChildNode($this); foreach ($this->getChildNodes() as $child) { $child->setChildNodeOf($this); } return $this; }