mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Add a Page::topParent() method to retrieve the topmost parent of a page
Adding to this branch as it's needed for the Admin change that handles this branch change
This commit is contained in:
parent
3eb2a5664a
commit
017500a6b5
|
|
@ -1716,6 +1716,31 @@ class Page
|
|||
return $pages->get($this->parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top parent object for this page
|
||||
*
|
||||
* @return Page|null the top parent page object if it exists.
|
||||
*/
|
||||
public function topParent()
|
||||
{
|
||||
$topParent = $this->parent();
|
||||
|
||||
if (!$topParent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$theParent = $topParent->parent();
|
||||
if ($theParent != null && $theParent->parent() !== null) {
|
||||
$topParent = $theParent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $topParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns children of this page.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user