Prevent circular node references

refs #149
This commit is contained in:
Alexander A. Klimov 2017-12-04 13:25:03 +01:00 committed by Jennifer Mourek
parent e5f7e30472
commit 1bc4b377ea

View file

@ -327,9 +327,12 @@ class AddNodeForm extends QuickForm
{
$list = array();
$parents = array();
$this->collectAllParents($this->parent, $parents);
$parents[$this->parent->getName()] = $this->parent;
foreach ($this->bp->getNodes() as $node) {
if ($node instanceof BpNode) {
// TODO: Blacklist parents
if ($node instanceof BpNode && ! isset($parents[$node->getName()])) {
$list[(string) $node] = (string) $node; // display name?
}
}
@ -338,6 +341,20 @@ class AddNodeForm extends QuickForm
return $list;
}
/**
* Collect the given node's parents recursively into the given array by their names
*
* @param BpNode $node
* @param BpNode[] $parents
*/
protected function collectAllParents(BpNode $node, array & $parents)
{
foreach ($node->getParents() as $parent) {
$parents[$parent->getName()] = $parent;
$this->collectAllParents($parent, $parents);
}
}
protected function fetchObjectList()
{
$this->objectList = array();