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
16
core/model/Hierarchy.php
Normal file → Executable file
16
core/model/Hierarchy.php
Normal file → Executable file
@ -560,6 +560,22 @@ class Hierarchy extends DataObjectDecorator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
* 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.
|
* then search the parents.
|
||||||
|
Loading…
Reference in New Issue
Block a user