<ol class="boxMenu">
{foreach from=$categoryList item=categoryItem}
- <li{if $activeCategory && $activeCategory->categoryID == $categoryItem->categoryID} class="active"{/if} data-category-id="{@$categoryItem->categoryID}">
- <a href="{@$categoryItem->getLink()}" class="boxMenuLink">
- <span class="boxMenuLinkTitle">{$categoryItem->getTitle()}</span>
- <span class="badge">{#$categoryItem->getArticles()}</span>
- </a>
-
- {if $categoryItem->hasChildren() && (!$categoryItem->parentCategoryID || ($activeCategory->categoryID == $categoryItem->categoryID || $activeCategory->isParentCategory($categoryItem->getDecoratedObject())))}
- <ol class="boxMenuDepth1">
- {foreach from=$categoryItem item=subCategoryItem}
- <li{if $activeCategory && $activeCategory->categoryID == $subCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subCategoryItem->categoryID}">
- <a href="{@$subCategoryItem->getLink()}" class="boxMenuLink">
- <span class="boxMenuLinkTitle">{$subCategoryItem->getTitle()}</span>
- <span class="badge">{#$subCategoryItem->getArticles()}</span>
- </a>
-
- {if $activeCategory && ($activeCategory->categoryID == $subCategoryItem->categoryID || $activeCategory->parentCategoryID == $subCategoryItem->categoryID) && $subCategoryItem->hasChildren()}
- <ol class="boxMenuDepth2">
- {foreach from=$subCategoryItem item=subSubCategoryItem}
- <li{if $activeCategory && $activeCategory->categoryID == $subSubCategoryItem->categoryID} class="active"{/if} data-category-id="{@$subSubCategoryItem->categoryID}">
- <a href="{@$subSubCategoryItem->getLink()}" class="boxMenuLink">
- <span class="boxMenuLinkTitle">{$subSubCategoryItem->getTitle()}</span>
- <span class="badge">{#$subSubCategoryItem->getArticles()}</span>
- </a>
- </li>
- {/foreach}
- </ol>
- {/if}
- </li>
- {/foreach}
- </ol>
- {/if}
- </li>
+ {if $categoryItem->isVisibleInNestedList($activeCategory)}
+ <li class="boxMenuItem boxMenuItemDepth{@$categoryItem->getDepth()}{if $activeCategory && $activeCategory->categoryID == $categoryItem->categoryID} active{/if}" data-category-id="{@$categoryItem->categoryID}">
+ <a href="{@$categoryItem->getLink()}" class="boxMenuLink">
+ <span class="boxMenuLinkTitle">{$categoryItem->getTitle()}</span>
+ <span class="badge">{#$categoryItem->getArticles()}</span>
+ </a>
+ </li>
+ {/if}
{/foreach}
{if $activeCategory}
public function valid() {
return isset($this->children[$this->index]);
}
+
+ /**
+ * Returns true if this category is visible in a nested menu item list.
+ *
+ * @param AbstractDecoratedCategory $activeCategory
+ * @return boolean
+ * @since 5.2
+ */
+ public function isVisibleInNestedList(AbstractDecoratedCategory $activeCategory = null) {
+ if (!$this->getParentCategory()) {
+ // level 1 is always visible
+ return true;
+ }
+
+ if ($activeCategory) {
+ if ($activeCategory->categoryID == $this->categoryID || $activeCategory->getDecoratedObject()->isParentCategory($this->getDecoratedObject())) {
+ // is the active category or a parent of the active category
+ return true;
+ }
+
+ if ($this->getParentCategory()->categoryID == $activeCategory->categoryID) {
+ // is a direct child element of the active category
+ return true;
+ }
+ }
+
+ return false;
+ }
}