diff --git a/library/Icinga/Web/Navigation/NavigationItem.php b/library/Icinga/Web/Navigation/NavigationItem.php index 6f65a3715..23d86d41b 100644 --- a/library/Icinga/Web/Navigation/NavigationItem.php +++ b/library/Icinga/Web/Navigation/NavigationItem.php @@ -667,7 +667,7 @@ class NavigationItem implements IteratorAggregate */ public function render() { - $this->getRenderer()->render($this); + $this->getRenderer()->setItem($this)->render(); } /** diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index 4b56b5f04..00a42d407 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -4,6 +4,7 @@ namespace Icinga\Web\Navigation\Renderer; use Icinga\Application\Icinga; +use Icinga\Exception\ProgrammingError; use Icinga\Util\String; use Icinga\Web\Navigation\NavigationItem; use Icinga\Web\View; @@ -20,6 +21,13 @@ class NavigationItemRenderer */ protected $view; + /** + * The item being rendered + * + * @var NavigationItem + */ + protected $item; + /** * The link target * @@ -83,6 +91,29 @@ class NavigationItemRenderer return $this->view; } + /** + * Set the navigation item to render + * + * @param NavigationItem $item + * + * @return $this + */ + public function setItem(NavigationItem $item) + { + $this->item = $item; + return $this; + } + + /** + * Return the navigation item being rendered + * + * @return NavigationItem + */ + public function getItem() + { + return $this->item; + } + /** * Set the link target * @@ -113,8 +144,17 @@ class NavigationItemRenderer * * @return string */ - public function render(NavigationItem $item) + public function render(NavigationItem $item = null) { + if ($item !== null) { + $this->setItem($item); + } elseif (($item = $this->getItem()) === null) { + throw new ProgrammingError( + 'Cannot render nothing. Pass the item to render as part' + . ' of the call to render() or set it with setItem()' + ); + } + $label = $this->view()->escape($item->getLabel()); if (($icon = $item->getIcon()) !== null) { $label = $this->view()->icon($icon) . $label;