private function _buildNavHtml($nodes, $parentId = 0, $level = 1)
{
// Do we have a maximum level?
$maxLevel = $this->_getParam('maxLevel', false);
if ($maxLevel !== false && $level > $maxLevel) {
return false;
}
// If we don't find any nodes at the end, don't return an empty UL
$foundNodes = false;
// Create UL
$nav = '';
if ($level == 1) {
if (!$this->_getParam('excludeUl', false)) {
$id = $this->_getParam('id', $this->_navigation->handle);
$class = $this->_getParam('class', 'nav');
$nav = sprintf("\n" . '<ul%1$s%2$s>', $id !== false ? ' id="' . $id . '"' : '', $class !== false ? ' class="' . $class . '"' : '');
}
} else {
$nav = sprintf("\n" . '<ul class="%1$s">', $this->_getParam('classLevel' . $level, 'nav__level' . $level));
}
// Add the nodes to the navigation, but only if they are enabled
$count = 0;
foreach ($nodes as $node) {
if ($node['parentId'] == $parentId && ($node['enabled'] || $this->_getParam('overrideStatus', false))) {
$count++;
$foundNodes = true;
// Get children
$children = $this->_buildNavHtml($nodes, $node['id'], $level + 1);
// Set node classes
$nodeClasses = array();
if ($children) {
$nodeClasses[] = $this->_getParam('classChildren', 'has-children');
}
if ($this->_isNodeActive($node)) {
$nodeClasses[] = $this->_getParam('classActive', 'active');
}
if ($this->_getParam('ignoreActiveChilds', false) === false) {
if ($this->_isChildActive($nodes, $node['id']) && !in_array($this->_getParam('classActive', 'active'), $nodeClasses)) {
$nodeClasses[] = $this->_getParam('classActive', 'active');
}
}
if ($level == 1 && $count == 1) {
$nodeClasses[] = $this->_getParam('classFirst', 'first');
}
if (!empty($node['listClass'])) {
$nodeClasses[] = $node['listClass'];
}
// Set hyperlink attributes
$hyperlinkAttributes = array('title="' . $node['name'] . '"');
if ($node['blank']) {
$hyperlinkAttributes[] = 'target="_blank"';
if ($this->_getParam('classBlank', false) !== false) {
$hyperlinkAttributes[] = 'class="' . $this->_getParam('classBlank', '') . '"';
}
}
if ($this->_getParam('linkRel', false) !== false) {
$hyperlinkAttributes[] = 'rel="' . $this->_getParam('linkRel', '') . '"';
}
// Add curent node
$nav .= sprintf("\n" . '<li%1$s><a href="%2$s"%4$s>%3$s</a>', count($nodeClasses) ? ' class="' . implode(' ', $nodeClasses) . '"' : '', $this->_parseUrl($node), $node['name'], ' ' . implode(' ', $hyperlinkAttributes));
// Add children to the navigation
if ($children) {
$nav .= $children;
}
$nav .= '</li>';
}
}
if ($level == 1) {
if (!$this->_getParam('excludeUl', false)) {
$nav .= "\n</ul>";
}
} else {
$nav .= "\n</ul>";
}
if ($foundNodes) {
return TemplateHelper::getRaw($nav);
} else {
return false;
}
}