Commit 33c43ae9 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(menu) add filter for menu items, creating space for https://github.com/opnsense/core/issues/508

Using this version, it will already be possible to "delete" (sub)menus from inherited structures, using the visibility="delete" tag on an item.

(cherry picked from commit d5378085)
parent f68e5534
......@@ -340,7 +340,7 @@ class MenuItem
public function toggleSelected($url)
{
$this->selected = false ;
foreach ($this->children as $nodeId => $node) {
foreach ($this->getFilteredChildren() as $nodeId => $node) {
$node->toggleSelected($url);
if ($node->getUrl() != "") {
$match = str_replace(array(".", "*","?"), array("\.", ".*","\?"), $node->getUrl());
......@@ -351,6 +351,23 @@ class MenuItem
}
}
/**
* Menu items are pluggable and can override already existing sections.
* This function filters the available child items and only return the still existing ones.
* @return array filtered set of children
*/
private function getFilteredChildren()
{
$result = array();
foreach ($this->children as $key => $node) {
if ($node->getVisibility() != 'delete') {
$result[$key] = $node;
}
}
ksort($result);
return $result;
}
/**
* Recursive method to retrieve a simple ordered structure of all menu items
* @return array named array containing menu items as simple objects to keep the api cleaner for our templates
......@@ -369,8 +386,7 @@ class MenuItem
}
// sort by order/id and map getters to array items
ksort($this->children);
foreach ($this->children as $key => $node) {
foreach ($this->getFilteredChildren() as $key => $node) {
$result[$node->id] = new \stdClass();
foreach ($properties as $methodName => $propName) {
$result[$node->id]->{$propName} = $node->$methodName();
......@@ -387,7 +403,7 @@ class MenuItem
*/
public function findNodeById($id)
{
foreach ($this->children as $key => $node) {
foreach ($this->getFilteredChildren() as $key => $node) {
if (strtolower($node->getId()) == strtolower($id)) {
return $node ;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment