From 14ae04b63154c33fcbcc01ff446a587260359f31 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 1 Oct 2015 17:43:48 +0200 Subject: [PATCH] RecursiveNavigationRenderer: Allow to enforce the standard item renderer --- .../Renderer/RecursiveNavigationRenderer.php | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Navigation/Renderer/RecursiveNavigationRenderer.php b/library/Icinga/Web/Navigation/Renderer/RecursiveNavigationRenderer.php index 83b2207bb..0417abef5 100644 --- a/library/Icinga/Web/Navigation/Renderer/RecursiveNavigationRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/RecursiveNavigationRenderer.php @@ -8,6 +8,7 @@ use RecursiveIteratorIterator; use Icinga\Exception\IcingaException; use Icinga\Web\Navigation\Navigation; use Icinga\Web\Navigation\NavigationItem; +use Icinga\Web\Navigation\Renderer\NavigationItemRenderer; /** * Renderer for multi level navigation @@ -25,6 +26,13 @@ class RecursiveNavigationRenderer extends RecursiveIteratorIterator implements N */ protected $content; + /** + * Whether to use the standard item renderer + * + * @var bool + */ + protected $useStandardRenderer; + /** * Create a new RecursiveNavigationRenderer * @@ -39,6 +47,29 @@ class RecursiveNavigationRenderer extends RecursiveIteratorIterator implements N ); } + /** + * Set whether to use the standard navigation item renderer + * + * @param bool $state + * + * @return $this + */ + public function setUseStandardItemRenderer($state = true) + { + $this->useStandardRenderer = (bool) $state; + return $this; + } + + /** + * Return whether to use the standard navigation item renderer + * + * @return bool + */ + public function getUseStandardItemRenderer() + { + return $this->useStandardRenderer; + } + /** * {@inheritdoc} */ @@ -131,7 +162,14 @@ class RecursiveNavigationRenderer extends RecursiveIteratorIterator implements N /** @var NavigationItem $item */ if ($item->shouldRender()) { $this->content[] = $this->getInnerIterator()->beginItemMarkup($item); - $this->content[] = $item->render(); + + if ($this->getUseStandardItemRenderer()) { + $renderer = new NavigationItemRenderer(); + $this->content[] = $renderer->render($item); + } else { + $this->content[] = $item->render(); + } + if (! $item->hasChildren()) { $this->content[] = $this->getInnerIterator()->endItemMarkup(); }