*/ class Mage_Page_Block_Html_Topmenu extends Mage_Core_Block_Template { /** * Top menu data tree * * @var Varien_Data_Tree_Node */ protected $_menu; /** * Init top menu tree structure */ public function _construct() { $this->_menu = new Varien_Data_Tree_Node(array(), 'root', new Varien_Data_Tree()); } /** * Get top menu html * * @param string $outermostClass * @param string $childrenWrapClass * @return string */ public function getHtml($outermostClass = '', $childrenWrapClass = '') { Mage::dispatchEvent('page_block_html_topmenu_gethtml_before', array( 'menu' => $this->_menu )); $this->_menu->setOutermostClass($outermostClass); $this->_menu->setChildrenWrapClass($childrenWrapClass); $html = $this->_getHtml($this->_menu, $childrenWrapClass); Mage::dispatchEvent('page_block_html_topmenu_gethtml_after', array( 'menu' => $this->_menu, 'html' => $html )); return $html; } /** * Recursively generates top menu html from data that is specified in $menuTree * * @param Varien_Data_Tree_Node $menuTree * @param string $childrenWrapClass * @return string */ protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass) { $html = ''; $children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1; $counter = 1; $childrenCount = $children->count(); $parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-'; foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter); $outermostClassCode = ''; $outermostClass = $menuTree->getOutermostClass(); if ($childLevel == 0 && $outermostClass) { $outermostClassCode = ' class="' . $outermostClass . '" '; $child->setClass($outermostClass); } $html .= '