public function render($key, array $items = [], array $options = [], $level = 1)
    {
        $i = 0;
        $output    = [];
        $options   = Hash::merge($this->_default, $options);
        $sorted    = Hash::sort($items, '{s}.weight', 'ASC');
        $itemCount = count($sorted);

        foreach ($sorted as $item) {
            $i++;
            $item = $this->_setFirstLast($i, $itemCount, $item);

            $children = false;
            if (count($item['children']) > 0) {
                $children = $this->render($key, $item['children'], $options, $level + 1);
            }

            $itemParams = [
                'options'  => $options,
                'item'     => $item,
                'count'    => $i,
                'children' => $children,
                'level'    => $level,
            ];

            $this->_setItemParams($itemParams);

            if (isset($item['callable']) && is_callable($item['callable'])) {
                $output[] = call_user_func_array($item['callable'], array_merge(['view' => $this->_View], $itemParams));
            } else {
                $output[] = $this->_View->element($options['itemElement'], $itemParams);
            }
        }

        $element = $this->_getCurrentMenuElement($options, $level);

        return $this->_View->element($element, [
            'content' => $output,
            'options' => $options,
        ]);
    }
public function render($key, array $items = [], array $options = [], $level = 1)
    {
        $i = 0;
        $output    = [];
        $options   = Hash::merge($this->_default, $options);
        $sorted    = Hash::sort($items, '{s}.weight', 'ASC');
        $itemCount = count($sorted);

        foreach ($sorted as $item) {
            $i++;
            $item = $this->_setFirstLast($i, $itemCount, $item);

            $children = false;
            if (count($item['children']) > 0) {
                $children = $this->render($key, $item['children'], $options, $level + 1);
            }

            $itemParams = [
                'options'  => $options,
                'item'     => $item,
                'count'    => $i,
                'children' => $children,
                'level'    => $level,
            ];

            $this->_setItemParams($itemParams);

            if (isset($item['callable']) && is_callable($item['callable'])) {
                $output[] = call_user_func_array($item['callable'], array_merge(['view' => $this->_View], $itemParams));
            } else {
                $output[] = $this->_View->element($options['itemElement'], $itemParams);
            }
        }

        $element = $this->_getCurrentMenuElement($options, $level);

        return $this->_View->element($element, [
            'content' => $output,
            'options' => $options,
        ]);
    }
public function render ( $ key , array $ items = [ ] , array $ options = [ ] , $ level = 1 ) { $ i = 0 ; $ output = [ ] ; $ options = Hash :: merge ( $ this -> _default , $ options ) ; $ sorted = Hash :: sort ( $ items , '{s}.weight' , 'ASC' ) ; $ itemCount = count ( $ sorted ) ; foreach ( $ sorted as $ item ) { $ i ++ ; $ item = $ this -> _setFirstLast ( $ i , $ itemCount , $ item ) ; $ children = false ; if ( count ( $ item [ 'children' ] ) > 0 ) { $ children = $ this -> render ( $ key , $ item [ 'children' ] , $ options , $ level + 1 ) ; } $ itemParams = [ 'options' => $ options , 'item' => $ item , 'count' => $ i , 'children' => $ children , 'level' => $ level , ] ; $ this -> _setItemParams ( $ itemParams ) ; if ( isset ( $ item [ 'callable' ] ) && is_callable ( $ item [ 'callable' ] ) ) { $ output [ ] = call_user_func_array ( $ item [ 'callable' ] , array_merge ( [ 'view' => $ this -> _View ] , $ itemParams ) ) ; } else { $ output [ ] = $ this -> _View -> element ( $ options [ 'itemElement' ] , $ itemParams ) ; } } $ element = $ this -> _getCurrentMenuElement ( $ options , $ level ) ; return $ this -> _View -> element ( $ element , [ 'content' => $ output , 'options' => $ options , ] ) ; }
Render menu.

@param string $key
@param array $items
@param array $options
@param int $level
@return string
@SuppressWarnings(PHPMD.ShortVariable)
Render menu .