mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Added Hierachy->getAncestors() to return all the parent objects of the class in a DataObjectSet.
From: Andrew Short <andrewjshort@gmail.com> git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88488 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
bf50f560df
commit
3defa4931c
18
core/model/Hierarchy.php
Normal file → Executable file
18
core/model/Hierarchy.php
Normal file → Executable file
@ -559,7 +559,23 @@ class Hierarchy extends DataObjectDecorator {
|
||||
return DataObject::get_one($this->owner->class, $filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all the parents of this class in a set ordered from the lowest to highest parent.
|
||||
*
|
||||
* @return DataObjectSet
|
||||
*/
|
||||
public function getAncestors() {
|
||||
$ancestors = new DataObjectSet();
|
||||
$object = $this->owner;
|
||||
|
||||
while($object = $object->getParent()) {
|
||||
$ancestors->push($object);
|
||||
}
|
||||
|
||||
return $ancestors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next node in the tree of the type. If there is no instance of the className descended from this node,
|
||||
* then search the parents.
|
||||
|
Loading…
Reference in New Issue
Block a user