private function build(NavigationNode $node, $entities) { foreach ($entities as $key => $entity) { if ($entity->getOwnerId() == 0 && $node->getParent() == null) { $node->addFromItem($entity); unset($entities[$key]); continue; } if ($node->getItem() == null) { continue; } if ($entity->getOwnerId() == $node->getItem()->getId()) { $node->addFromItem($entity); unset($entities[$key]); } } if (count($entities) > 0) { foreach ($node->getChildren() as $child) { $child = $this->build($child, $entities); } } return $node; }