diff --git a/src/Pingpong/Menus/MenuItem.php b/src/Pingpong/Menus/MenuItem.php index b8002816..d96c61fa 100644 --- a/src/Pingpong/Menus/MenuItem.php +++ b/src/Pingpong/Menus/MenuItem.php @@ -25,7 +25,7 @@ class MenuItem implements ArrayableContract { * * @var array */ - protected $fillable = array('url', 'route', 'title', 'name', 'icon', 'parent', 'attributes'); + protected $fillable = array('url', 'route', 'title', 'name', 'icon', 'parent', 'attributes', 'active'); /** * Constructor. @@ -281,7 +281,9 @@ public function getProperties() */ public function getAttributes() { - return HTML::attributes($this->attributes); + $attributes = array_forget($this->attributes, 'active'); + + return HTML::attributes($attributes); } /** @@ -348,7 +350,11 @@ public function hasActiveOnChild() { foreach ($this->getChilds() as $child) { - if ($child->hasRoute() && $child->getActiveStateFromRoute()) + if ($child->isActive()) + { + $isActive = true; + } + elseif ($child->hasRoute() && $child->getActiveStateFromRoute()) { $isActive = true; } @@ -362,6 +368,16 @@ public function hasActiveOnChild() return $isActive; } + /** + * Get active attribute. + * + * @return string + */ + public function getActiveAttribute() + { + return array_get($this->attributes, 'active'); + } + /** * Get active state for current item. * @@ -369,6 +385,15 @@ public function hasActiveOnChild() */ public function isActive() { + $active = $this->getActiveAttribute(); + + if (is_bool($active)) return $active; + + if ($active instanceof \Closure) + { + return call_user_func($active); + } + if ($this->hasRoute()) { return $this->getActiveStateFromRoute();