Use default MenuItemRenderer as renderer if no custom renderer is set
refs #7658
This commit is contained in:
parent
f543321ac4
commit
4eb5f75c62
|
@ -4,6 +4,7 @@
|
||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Icinga\Web\Menu\MenuItemRenderer;
|
||||||
use RecursiveIteratorIterator;
|
use RecursiveIteratorIterator;
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Web\Menu\PermittedMenuItemFilter;
|
use Icinga\Web\Menu\PermittedMenuItemFilter;
|
||||||
|
@ -32,6 +33,11 @@ class MenuRenderer extends RecursiveIteratorIterator
|
||||||
*/
|
*/
|
||||||
protected $useCustomRenderer = false;
|
protected $useCustomRenderer = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var MenuItemRenderer
|
||||||
|
*/
|
||||||
|
protected $defaultRenderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new MenuRenderer
|
* Create a new MenuRenderer
|
||||||
*
|
*
|
||||||
|
@ -45,6 +51,7 @@ class MenuRenderer extends RecursiveIteratorIterator
|
||||||
} else {
|
} else {
|
||||||
$this->url = Url::fromPath($url);
|
$this->url = Url::fromPath($url);
|
||||||
}
|
}
|
||||||
|
$this->defaultRenderer = new MenuItemRenderer();
|
||||||
parent::__construct(new PermittedMenuItemFilter($menu), RecursiveIteratorIterator::CHILD_FIRST);
|
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());
|
Logger::error('Could not invoke custom renderer. Exception: '. $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($child->getIcon() && strpos($child->getIcon(), '.') === false) {
|
|
||||||
return sprintf(
|
return $this->defaultRenderer->render($child);
|
||||||
'<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())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue