src/Menu/MenuConfigInterpreter.php
protected function filterNestedEmptyGroups(MenuPresenceInterface $presence)
    {
        if ($presence->type() !== MenuPresenceType::GROUP) {
            return 1;
        }

        $children = $presence->children();

        if ( ! $children || ! count($children)) {
            return 0;
        }

        $remove        = [];
        $nonGroupCount = 0;

        foreach ($children as $key => $childPresence) {

            if ( ! $this->filterNestedEmptyGroups($childPresence)) {
                $remove[] = $key;
                continue;
            }

            $nonGroupCount++;
        }

        foreach ($remove as $key) {
            unset($children[$key]);
        }

        $presence->setChildren($children);

        return $nonGroupCount;
    }
protected function filterNestedEmptyGroups(MenuPresenceInterface $presence)
    {
        if ($presence->type() !== MenuPresenceType::GROUP) {
            return 1;
        }

        $children = $presence->children();

        if ( ! $children || ! count($children)) {
            return 0;
        }

        $remove        = [];
        $nonGroupCount = 0;

        foreach ($children as $key => $childPresence) {

            if ( ! $this->filterNestedEmptyGroups($childPresence)) {
                $remove[] = $key;
                continue;
            }

            $nonGroupCount++;
        }

        foreach ($remove as $key) {
            unset($children[$key]);
        }

        $presence->setChildren($children);

        return $nonGroupCount;
    }
protected function filterNestedEmptyGroups ( MenuPresenceInterface $ presence ) { if ( $ presence -> type ( ) !== MenuPresenceType :: GROUP ) { return 1 ; } $ children = $ presence -> children ( ) ; if ( ! $ children || ! count ( $ children ) ) { return 0 ; } $ remove = [ ] ; $ nonGroupCount = 0 ; foreach ( $ children as $ key => $ childPresence ) { if ( ! $ this -> filterNestedEmptyGroups ( $ childPresence ) ) { $ remove [ ] = $ key ; continue ; } $ nonGroupCount ++ ; } foreach ( $ remove as $ key ) { unset ( $ children [ $ key ] ) ; } $ presence -> setChildren ( $ children ) ; return $ nonGroupCount ; }
Removes any empty group children from a tree structure, returning
the number of non-group entries.

@param MenuPresenceInterface $presence
@return int  the number of non-group children found on the levels below
Removes any empty group children from a tree structure returning the number of non - group entries .