protected function generateTree(Collection $collection, Collection $children)
    {
        $children->map(function (AdminMenuInterface $menuItem) use ($collection, &$tree) {
            $tree[] = [
                'routeName' => $menuItem->getRouteName(),
                'cssClass'  => $menuItem->getCssClass(),
                'name'      => $menuItem->getName(),
                'children'  => $this->generateTree($collection, $this->filterElements($collection, $menuItem))
            ];
        });
        
        return $tree;
    }
protected function generateTree(Collection $collection, Collection $children)
    {
        $children->map(function (AdminMenuInterface $menuItem) use ($collection, &$tree) {
            $tree[] = [
                'routeName' => $menuItem->getRouteName(),
                'cssClass'  => $menuItem->getCssClass(),
                'name'      => $menuItem->getName(),
                'children'  => $this->generateTree($collection, $this->filterElements($collection, $menuItem))
            ];
        });
        
        return $tree;
    }
protected function generateTree ( Collection $ collection , Collection $ children ) { $ children -> map ( function ( AdminMenuInterface $ menuItem ) use ( $ collection , & $ tree ) { $ tree [ ] = [ 'routeName' => $ menuItem -> getRouteName ( ) , 'cssClass' => $ menuItem -> getCssClass ( ) , 'name' => $ menuItem -> getName ( ) , 'children' => $ this -> generateTree ( $ collection , $ this -> filterElements ( $ collection , $ menuItem ) ) ] ; } ) ; return $ tree ; }
Generates a tree for given children elements

@param Collection $collection
@param Collection $children

@return array
Generates a tree for given children elements