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->add_on_new('basico', '', 'Geografico', '', Array(), -1);
$sidebar->create_submenu('teste', 'Teste');
//$sidebar->add_on_new('teste', '', 'Elemento');
echo $sidebar->render(); echo $sidebar->render();
+10 -3
View File
@@ -67,6 +67,7 @@ class MenuItem {
$this->link = $link; $this->link = $link;
return $this; return $this;
} }
/** /**
* Set the menu item name. * Set the menu item name.
* *
@@ -77,6 +78,7 @@ class MenuItem {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }
/** /**
* Set the menu item title. * Set the menu item title.
* *
@@ -119,7 +121,7 @@ class MenuItem {
$this->nested = $menu; $this->nested = $menu;
return $this; return $this;
} }
/** /**
* Nest another menu. * Nest another menu.
* *
@@ -128,7 +130,7 @@ class MenuItem {
*/ */
public function nested() { public function nested() {
return $this->nested; return $this->nested;
} }
/** /**
* Render the menu item. * Render the menu item.
@@ -136,7 +138,12 @@ class MenuItem {
* @return string * @return string
*/ */
public function render() { 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>';
}
} }
/** /**