Now, if a submenu is empty, it will not be rendered

This commit is contained in:
Artur
2019-01-31 23:53:19 -02:00
parent 8cb8e98154
commit a8051dda4d
2 changed files with 14 additions and 3 deletions
+4
View File
@@ -16,4 +16,8 @@ $sidebar->create_submenu('administrativo', 'Administrativo');
$sidebar->add_on_new('basico', '', 'Geografico', '', Array(), -1);
$sidebar->create_submenu('teste', 'Teste');
//$sidebar->add_on_new('teste', '', 'Elemento');
echo $sidebar->render();
+8 -1
View File
@@ -67,6 +67,7 @@ class MenuItem {
$this->link = $link;
return $this;
}
/**
* Set the menu item name.
*
@@ -77,6 +78,7 @@ class MenuItem {
$this->name = $name;
return $this;
}
/**
* Set the menu item title.
*
@@ -136,7 +138,12 @@ class MenuItem {
* @return string
*/
public function render() {
return '<li>' . $this->html->link($this->link, $this->title, $this->icon, $this->attributes) . $this->renderNestedMenu() . '</li>';
if( empty($this->nested) ){
return '<li>' . $this->html->link($this->link, $this->title, $this->icon, $this->attributes) . '</li>';
}
if ( !empty($this->nested->items()) ) {
return '<li>' . $this->html->link($this->link, $this->title, $this->icon, $this->attributes) . $this->renderNestedMenu() . '</li>';
}
}
/**