public function render()
{
if ('BE' === TYPO3_MODE) {
return '';
}
$pageUid = (int) $this->arguments['pageUid'];
if (0 === $pageUid) {
$pageUid = $GLOBALS['TSFE']->id;
}
$queryStringMethod = $this->arguments['queryStringMethod'];
if (!in_array($queryStringMethod, ['GET', 'POST', 'GET,POST'], true)) {
throw new \InvalidArgumentException('The parameter "queryStringMethods" must be one of "GET", "POST" or "GET,POST".', 1475337546);
}
$uriBuilder = $this->controllerContext->getUriBuilder();
$uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setUseCacheHash(true)->setCreateAbsoluteUri(true)->setAddQueryString(true)->setAddQueryStringMethod($queryStringMethod)->setArgumentsToBeExcludedFromQueryString(['id'])->build();
if (true === empty($uri)) {
return null;
}
$uri = $GLOBALS['TSFE']->baseUrlWrap($uri);
$this->tag->addAttribute('rel', 'canonical');
$this->tag->addAttribute('href', $uri, false);
$renderedTag = $this->tag->render();
if (1 === (int) $GLOBALS['TSFE']->config['config']['disableAllHeaderCode']) {
return $renderedTag;
}
static::getPageRenderer()->addMetaTag($renderedTag);
}