diff --git a/application/forms/Navigation/NavigationItemForm.php b/application/forms/Navigation/NavigationItemForm.php index cd6eca70d..4e63cab56 100644 --- a/application/forms/Navigation/NavigationItemForm.php +++ b/application/forms/Navigation/NavigationItemForm.php @@ -38,10 +38,10 @@ class NavigationItemForm extends Form 'label' => $this->translate('Target'), 'description' => $this->translate('The target where to open this navigation item\'s url'), 'multiOptions' => array( - '_blank' => $this->translate('New Window'), - '_next' => $this->translate('New Column'), - '_main' => $this->translate('Single Column'), - '_self' => $this->translate('Current Column') + 'new_window' => $this->translate('New Window'), + 'next_column' => $this->translate('New Column'), + 'single_column' => $this->translate('Single Column'), + 'current_column' => $this->translate('Current Column') ) ) ); diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 5bebde085..052e19412 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -361,7 +361,7 @@ class Web extends EmbeddedWeb 'logout' => array( 'label' => t('Logout'), 'priority' => 200, - 'target' => '_self', + 'target' => 'current_window', 'url' => 'authentication/logout' ) ) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index 3b739c320..0f22de40b 100644 --- a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php +++ b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php @@ -36,6 +36,13 @@ class NavigationItemRenderer */ protected $internalLinkTargets; + /** + * Native HTML link targets + * + * @var array + */ + protected $htmlLinkTargets; + /** * Whether to escape the label * @@ -54,7 +61,15 @@ class NavigationItemRenderer $this->setOptions($options); } - $this->internalLinkTargets = array('_main', '_self', '_next'); + $this->internalLinkTargets = array( + 'single_column' => '_main', + 'current_column' => '_self', + 'next_column' => '_next' + ); + $this->htmlLinkTargets = array( + 'current_window' => '_self', + 'new_window' => '_blank' + ); $this->init(); } @@ -185,7 +200,7 @@ class NavigationItemRenderer $url->overwriteParams($item->getUrlParameters()); $target = $item->getTarget(); - if ($url->isExternal() && (!$target || in_array($target, $this->internalLinkTargets, true))) { + if ($url->isExternal() && ! ($target && $this->getIcingaLinkTarget($target) === null)) { $url = Url::fromPath('iframe', array('url' => $url)); } @@ -222,10 +237,43 @@ class NavigationItemRenderer return ''; } - if (! in_array($target, $this->internalLinkTargets, true)) { - return ' target="' . $this->view()->escape($target) . '"'; + $icingaTarget = $this->getIcingaLinkTarget($target); + if ($icingaTarget !== null) { + return ' data-base-target="' . $icingaTarget . '"'; } - return ' data-base-target="' . $target . '"'; + $htmlTarget = $this->getHtmlLinkTarget($target); + return ' target="' . ($htmlTarget === null ? $this->view()->escape($target) : $htmlTarget) . '"'; + } + + /** + * If $targetName is an internal link target, return its HTML version. Otherwise, return null. + * + * @param string $targetName + * + * @return string|null + */ + protected function getIcingaLinkTarget($targetName) + { + if (isset($this->internalLinkTargets[$targetName])) { + return $this->internalLinkTargets[$targetName]; + } + if (in_array($targetName, $this->internalLinkTargets, true)) { + return $targetName; + } + } + + /** + * If $targetName is an HTML link target, return its HTML version. Otherwise, return null. + * + * @param string $targetName + * + * @return string|null + */ + protected function getHtmlLinkTarget($targetName) + { + if (isset($this->htmlLinkTargets[$targetName])) { + return $this->htmlLinkTargets[$targetName]; + } } }