/** * Renders menu tree. Internal method. * * @param MenuItem $item Menu item * @param integer $depth The depth of children to render * @param boolean $renderAsChild Render with attributes on the li (true) or the ul around the children (false) * * @return string */ protected function doRender(MenuItem $item, $depth = null, $renderAsChild = false) { /** * Return an empty string if any of the following are true: * a) The menu has no children eligible to be displayed * b) The depth is 0 * c) This menu item has been explicitly set to hide its children */ if (!$item->hasChildren() || $depth === 0 || !$item->getShowChildren()) { return ''; } if ($renderAsChild) { $attributes = array('class' => 'menu_level_' . $item->getLevel()); } else { $attributes = $item->getAttributes(); } // render children with a depth - 1 $childDepth = $depth === null ? null : $depth - 1; $html = $this->format('<ul' . $this->renderHtmlAttributes($attributes) . '>', 'ul', $item->getLevel()); $html .= $this->renderChildren($item, $childDepth); $html .= $this->format('</ul>', 'ul', $item->getLevel()); return $html; }