Merge branch 'bugfix/logout-requires-restart-of-browser-10330'

fixes #10330
This commit is contained in:
Alexander A. Klimov 2015-12-17 18:09:49 +01:00
commit 94f4c670c1
3 changed files with 58 additions and 10 deletions

View File

@ -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')
)
)
);

View File

@ -361,7 +361,7 @@ class Web extends EmbeddedWeb
'logout' => array(
'label' => t('Logout'),
'priority' => 200,
'target' => '_self',
'target' => 'current_window',
'url' => 'authentication/logout'
)
)

View File

@ -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];
}
}
}