From 4cf8da4bb9bd0bf09cb80ac82b79852126e7ba0c Mon Sep 17 00:00:00 2001 From: Matthias Jentsch <matthias.jentsch@netways.de> Date: Mon, 29 Dec 2014 13:30:54 +0100 Subject: [PATCH] Do not focus logout menu item after a recurring login Implement new MenuItemRenderer made for pages that are not part of the regular site navigation and should trigger a complete site reload instead of handling it via XHR. --- library/Icinga/Web/Menu.php | 3 ++- .../Web/Menu/ForeignMenuItemRenderer.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 library/Icinga/Web/Menu/ForeignMenuItemRenderer.php diff --git a/library/Icinga/Web/Menu.php b/library/Icinga/Web/Menu.php index 18a17ea67..a74112dc4 100644 --- a/library/Icinga/Web/Menu.php +++ b/library/Icinga/Web/Menu.php @@ -248,7 +248,8 @@ class Menu implements RecursiveIterator $section->add(t('Logout'), array( 'url' => 'authentication/logout', - 'priority' => 700 + 'priority' => 700, + 'renderer' => 'ForeignMenuItemRenderer' )); } } diff --git a/library/Icinga/Web/Menu/ForeignMenuItemRenderer.php b/library/Icinga/Web/Menu/ForeignMenuItemRenderer.php new file mode 100644 index 000000000..659709868 --- /dev/null +++ b/library/Icinga/Web/Menu/ForeignMenuItemRenderer.php @@ -0,0 +1,24 @@ +<?php +// {{{ICINGA_LICENSE_HEADER}}} +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Web\Menu; + +use Icinga\Web\Menu; +use Icinga\Web\Url; + +/** + * A menu item with a link that surpasses the regular navigation link behavior + */ +class ForeignMenuItemRenderer implements MenuItemRenderer { + + public function render(Menu $menu) + { + return sprintf( + '<a href="%s" target="_self">%s%s<span></span></a>', + $menu->getUrl() ?: '#', + $menu->getIcon() ? '<img src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '', + htmlspecialchars($menu->getTitle()) + ); + } +}