RecursiveNavigationRenderer: Allow to enforce the standard item renderer

This commit is contained in:
Johannes Meyer 2015-10-01 17:43:48 +02:00
parent 8c8af9cd50
commit 14ae04b631
1 changed files with 39 additions and 1 deletions

View File

@ -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();
}