src/View/Helper/MenuHelper.php
public function renderTree($menuItems, $level = null)
    {
        $output = '';

        $depth = ($level !== null) ? $level : 1;

        foreach ($menuItems as $key => $menuItem) {
            $classes = ['menu-item'];
            $menuItemRow = $this->_View->element('../Menus/__menu-item-row', [
                'menuItem' => $menuItem,
                'level' => $level
            ]);

            if (!empty($menuItem['children'])) {
                $menuItemRow .= '<ul>' . $this->renderTree($menuItem['children'], $depth + 1) . '</ul>';
            } else {
                $classes[] = 'no-children';
            }
            $output .= '<li class="' . join(' ', $classes) . '" data-menu-item-id="' . $menuItem['id'] . '">' . $menuItemRow . '</li>';
        }

        return $output;
    }
public function renderTree($menuItems, $level = null)
    {
        $output = '';

        $depth = ($level !== null) ? $level : 1;

        foreach ($menuItems as $key => $menuItem) {
            $classes = ['menu-item'];
            $menuItemRow = $this->_View->element('../Menus/__menu-item-row', [
                'menuItem' => $menuItem,
                'level' => $level
            ]);

            if (!empty($menuItem['children'])) {
                $menuItemRow .= '<ul>' . $this->renderTree($menuItem['children'], $depth + 1) . '</ul>';
            } else {
                $classes[] = 'no-children';
            }
            $output .= '<li class="' . join(' ', $classes) . '" data-menu-item-id="' . $menuItem['id'] . '">' . $menuItemRow . '</li>';
        }

        return $output;
    }
public function renderTree ( $ menuItems , $ level = null ) { $ output = '' ; $ depth = ( $ level !== null ) ? $ level : 1 ; foreach ( $ menuItems as $ key => $ menuItem ) { $ classes = [ 'menu-item' ] ; $ menuItemRow = $ this -> _View -> element ( '../Menus/__menu-item-row' , [ 'menuItem' => $ menuItem , 'level' => $ level ] ) ; if ( ! empty ( $ menuItem [ 'children' ] ) ) { $ menuItemRow .= '<ul>' . $ this -> renderTree ( $ menuItem [ 'children' ] , $ depth + 1 ) . '</ul>' ; } else { $ classes [ ] = 'no-children' ; } $ output .= '<li class="' . join ( ' ' , $ classes ) . '" data-menu-item-id="' . $ menuItem [ 'id' ] . '">' . $ menuItemRow . '</li>' ; } return $ output ; }
Used to render menu items as a ul li fake table
in the backend.

@param array $menuItems The menu items to render as tree.
@param null|int $level The current level.
@return string
Used to render menu items as a ul li fake table in the backend .