/**
* Set the parent of this category
*
* If the category already has a parent, the link is unset
*
* @param CategoryNode|null $parent CategoryNode for the parent to be set or null
*
* @return void
*
* @since 1.6
*/
public function setParent(NodeInterface $parent)
{
if (!\is_null($this->_parent)) {
$key = array_search($this, $this->_parent->_children);
unset($this->_parent->_children[$key]);
}
$this->_parent = $parent;
$this->_parent->_children[] =& $this;
if (\count($this->_parent->_children) > 1) {
end($this->_parent->_children);
$this->_leftSibling = prev($this->_parent->_children);
$this->_leftSibling->_rightsibling =& $this;
}
if ($this->parent_id != 1) {
$this->_path = $parent->getPath();
}
$this->_path[$this->id] = $this->id . ':' . $this->alias;
}