I'm trying to override the __getHtml function in topmenu.php
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{
protected function _getHtml(
\Magento\Framework\Data\Tree\Node $menuTree,
$childrenWrapClass,
$limit,
array $colBrakes = []
) {
$html = '';
$children = $menuTree->getChildren();
$childLevel = $this->getChildLevel($menuTree->getLevel());
$this->removeChildrenWithoutActiveParent($children, $childLevel);
$counter = 1;
$childrenCount = $children->count();
$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';
/** @var Node $child */
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 . '" ';
$this->setCurrentClass($child, $outermostClass);
}
if ($this->shouldAddNewColumn($colBrakes, $counter)) {
$html .= '</ul></li><li class="column"><ul>';
}
$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml(
$child->getName()
) . '</span></a>' . $this->_addSubMenu(
$child,
$childLevel,
$childrenWrapClass,
$limit
) . '</li>';
$counter++;
}
if (is_array($colBrakes) && !empty($colBrakes) && $limit) {
$html = '<li class="column"><ul>' . $html . '</ul></li>';
}
return $html;
}
}
It's the original function because I first wanted to test the override. But this makes the navbar completely disappear.
Overriding another function like _addSubMenu works, though.