From 5edd8df1b6246925aea62325719236035b539271 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 17 Dec 2015 16:13:12 +0100 Subject: [PATCH] NavigationItemRenderer: provide more human-readable aliases for native HTML link targets refs #10330 --- .../Renderer/NavigationItemRenderer.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php b/library/Icinga/Web/Navigation/Renderer/NavigationItemRenderer.php index b1a010ec5..1fcf5677e 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 * @@ -59,6 +66,10 @@ class NavigationItemRenderer 'current_column' => '_self', 'next_column' => '_next' ); + $this->htmlLinkTargets = array( + 'current_window' => '_self', + 'new_window' => '_blank' + ); $this->init(); } @@ -227,26 +238,29 @@ class NavigationItemRenderer } $actualTarget = $this->actualLinkTarget($target); - if ($actualTarget === null) { - return ' target="' . $this->view()->escape($target) . '"'; + if ($actualTarget !== null) { + return ' data-base-target="' . $actualTarget . '"'; } - return ' data-base-target="' . $actualTarget . '"'; + $actualTarget = $this->actualLinkTarget($target, false); + return ' target="' . ($actualTarget === null ? $this->view()->escape($target) : $actualTarget) . '"'; } /** - * If $target is an internal linktarget, return its HTML version. Otherwise, return null. + * If $target is a linktarget, return its HTML version. Otherwise, return null. * * @param string $target + * @param bool $internal Whether the target must or must not be provided by Icinga Web 2 * * @return string|null */ - protected function actualLinkTarget($target) + protected function actualLinkTarget($target, $internal = true) { - if (isset($this->internalLinkTargets[$target])) { - return $this->internalLinkTargets[$target]; + $linkTargets = $internal ? $this->internalLinkTargets : $this->htmlLinkTargets; + if (isset($linkTargets[$target])) { + return $linkTargets[$target]; } - if (in_array($target, $this->internalLinkTargets, true)) { + if (in_array($target, $linkTargets, true)) { return $target; } }