$children[$link['parent'
]][$id] =
$id;
} else { // A top level link - we need them to root our tree.
$top_links[$id] =
$id;
$link['parent'
] = '';
} $links[$id] =
$link;
} } foreach ($top_links as $id) { $this->
saveRecursive($id,
$children,
$links);
} // Handle any children we didn't find starting from top-level links.
foreach ($children as $orphan_links) { foreach ($orphan_links as $id) { // Check for a parent that is not loaded above since only internal links
// are loaded above.
$parent =
$this->
loadFull($links[$id]['parent'
]);
// If there is a parent add it to the links to be used in
// ::saveRecursive().
if ($parent) { $links[$links[$id]['parent'
]] =
$parent;
}