parent
c03109c4c6
commit
62f7a49a45
|
@ -224,30 +224,21 @@ class NavigationItem implements Countable, IteratorAggregate
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a child item to this item
|
* Add a child to this item
|
||||||
*
|
*
|
||||||
* Bubbles active state.
|
* If the child is active this item gets activated as well.
|
||||||
*
|
*
|
||||||
* @param NavigationItem|array $child The child to add
|
* @param NavigationItem $child
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws InvalidArgumentException If the child argument is invalid
|
|
||||||
*/
|
*/
|
||||||
public function addChild($child)
|
public function addChild(NavigationItem $child)
|
||||||
{
|
{
|
||||||
if (! $child instanceof NavigationItem) {
|
$this->getChildren()->addItem($child->setParent($this));
|
||||||
if (! is_array($child)) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
'Argument child must be either an array or an instance of NavigationItem'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$child = new NavigationItem($child);
|
|
||||||
}
|
|
||||||
$child->parent = $this;
|
|
||||||
$this->children->addItem($child);
|
|
||||||
if ($child->getActive()) {
|
if ($child->getActive()) {
|
||||||
$this->setActive();
|
$this->setActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue