src/Menu/MenuBuilder.php
public function getParentMenu(Menu $menu, MenuItem $childNode)
    {
        $itemIterator = new RecursiveItemIterator($menu->getIterator());
        $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($iterator as $menuItem) {
            $parentId = $childNode->getParent()->getId();
            if ($menuItem->getName() != $parentId) {
                continue;
            }

            return $menuItem;
        }

        return false;
    }
public function getParentMenu(Menu $menu, MenuItem $childNode)
    {
        $itemIterator = new RecursiveItemIterator($menu->getIterator());
        $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($iterator as $menuItem) {
            $parentId = $childNode->getParent()->getId();
            if ($menuItem->getName() != $parentId) {
                continue;
            }

            return $menuItem;
        }

        return false;
    }
public function getParentMenu ( Menu $ menu , MenuItem $ childNode ) { $ itemIterator = new RecursiveItemIterator ( $ menu -> getIterator ( ) ) ; $ iterator = new \ RecursiveIteratorIterator ( $ itemIterator , \ RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ iterator as $ menuItem ) { $ parentId = $ childNode -> getParent ( ) -> getId ( ) ; if ( $ menuItem -> getName ( ) != $ parentId ) { continue ; } return $ menuItem ; } return false ; }
Recursively get parents.

@param $menu - menu to look for the parent in
@param $childNode - menu node whose parent we are looking for

@return mixed
Recursively get parents .