Back to ImmutableNodeTrait class

Method getRoot

public \Joomla\CMS\Tree\ImmutableNodeInterface
getRoot
()
Get the root of the tree
Returns
  • \Joomla\CMS\Tree\ImmutableNodeInterface
Since
  • 4.0.0

Method getRoot - Source code

/**
 * Get the root of the tree
 *
 * @return  ImmutableNodeInterface
 *
 * @since   4.0.0
 */
public function getRoot()
{
    $root = $this->getParent();
    if (!$root) {
        return $this;
    }
    while ($root->hasParent()) {
        $root = $root->getParent();
    }
    return $root;
}