Use default MenuItemRenderer as renderer if no custom renderer is set

refs #7658
This commit is contained in:
Alexander Fuhr 2015-04-20 17:04:46 +02:00
parent f543321ac4
commit 4eb5f75c62
1 changed files with 9 additions and 16 deletions

View File

@ -4,6 +4,7 @@
namespace Icinga\Web;
use Exception;
use Icinga\Web\Menu\MenuItemRenderer;
use RecursiveIteratorIterator;
use Icinga\Application\Logger;
use Icinga\Web\Menu\PermittedMenuItemFilter;
@ -32,6 +33,11 @@ class MenuRenderer extends RecursiveIteratorIterator
*/
protected $useCustomRenderer = false;
/**
* @var MenuItemRenderer
*/
protected $defaultRenderer;
/**
* Create a new MenuRenderer
*
@ -45,6 +51,7 @@ class MenuRenderer extends RecursiveIteratorIterator
} else {
$this->url = Url::fromPath($url);
}
$this->defaultRenderer = new MenuItemRenderer();
parent::__construct(new PermittedMenuItemFilter($menu), RecursiveIteratorIterator::CHILD_FIRST);
}
@ -114,22 +121,8 @@ class MenuRenderer extends RecursiveIteratorIterator
Logger::error('Could not invoke custom renderer. Exception: '. $e->getMessage());
}
}
if ($child->getIcon() && strpos($child->getIcon(), '.') === false) {
return sprintf(
'<a href="%s"><i aria-hidden="true" class="icon-%s"></i>%s</a>',
$child->getUrl() ?: '#',
$child->getIcon(),
htmlspecialchars($child->getTitle())
);
}
return sprintf(
'<a href="%s">%s%s</a>',
$child->getUrl() ?: '#',
$child->getIcon()
? '<img aria-hidden="true" src="' . Url::fromPath($child->getIcon()) . '" class="icon" /> '
: '',
htmlspecialchars($child->getTitle())
);
return $this->defaultRenderer->render($child);
}
/**