#52997Link/PageViewHelper don't respect target set in backend link field
Description
Hi,
Just recently decovered that the default Link/PageViewHelper don’t respect targets set in backend, so the _blank, _top is not respected by the viewhelper.
I’ve currently a small patch for this, but needs some more cleanup before commiting it.
Just want to know if this is a issue needed to be fixed in general otherwise i’ll just use a local viewhelper.
Currently the fix is as this:
public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array()) {
// New line
$urlTarget = $this->checkUrlTarget($pageUid);
$uriBuilder = $this->controllerContext->getUriBuilder();
$uri = $uriBuilder
->reset()
->setTargetPageUid($pageUid)
->setTargetPageType($pageType)
->setNoCache($noCache)
->setUseCacheHash(!$noCacheHash)
->setSection($section)
->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
->setArguments($additionalParams)
->setCreateAbsoluteUri($absolute)
->setAddQueryString($addQueryString)
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
->build();
$this->tag->addAttribute('href', $uri);
if($urlTarget) {
$this->tag->addAttribute('target', $urlTarget);
}
$this->tag->setContent($this->renderChildren());
return $this->tag->render();
}
/**
* Check the Url target
*
* @param $url The url of the page linked to.
* @return mixed NULL if target not set, and string with target if set.
*/
protected function checkUrlTarget($url) {
$urlTarget = NULL;
$allowedTargets = array('_blank', '_top', '_new');
$urlArray = explode(' ', $url);
if(!empty($urlArray[1]) && in_array($urlArray[1], $allowedTargets)) {
$urlTarget = $urlArray[1];
}
return $urlTarget;
}
Let me know what you think?
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.