src/Menu/MenuBuilder.php
public function showOnlyCurrentChildren(ItemInterface $menu)
    {
        $itemIterator = new RecursiveItemIterator($menu->getIterator());

        $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($iterator as $menuItem) {
            /** @var \Knp\Menu\MenuItem $menuItem */
            if (!$this->matcher->isCurrent($menuItem) && !$this->matcher->isAncestor($menuItem)) {
                $menuItem->setDisplayChildren(false);
            }
        }
    }
public function showOnlyCurrentChildren(ItemInterface $menu)
    {
        $itemIterator = new RecursiveItemIterator($menu->getIterator());

        $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($iterator as $menuItem) {
            /** @var \Knp\Menu\MenuItem $menuItem */
            if (!$this->matcher->isCurrent($menuItem) && !$this->matcher->isAncestor($menuItem)) {
                $menuItem->setDisplayChildren(false);
            }
        }
    }
public function showOnlyCurrentChildren ( ItemInterface $ menu ) { $ itemIterator = new RecursiveItemIterator ( $ menu -> getIterator ( ) ) ; $ iterator = new \ RecursiveIteratorIterator ( $ itemIterator , \ RecursiveIteratorIterator :: SELF_FIRST ) ; foreach ( $ iterator as $ menuItem ) { /** @var \Knp\Menu\MenuItem $menuItem */ if ( ! $ this -> matcher -> isCurrent ( $ menuItem ) && ! $ this -> matcher -> isAncestor ( $ menuItem ) ) { $ menuItem -> setDisplayChildren ( false ) ; } } }
Set the children menu item nodes to be shown only if the node
is current or the parent is a current ancestor.

@param ItemInterface $menu
Set the children menu item nodes to be shown only if the node is current or the parent is a current ancestor .