‪TYPO3CMS  9.5
PageViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
18 
64 class ‪PageViewHelper extends AbstractTagBasedViewHelper
65 {
69  protected ‪$tagName = 'a';
70 
74  public function ‪initializeArguments()
75  {
76  parent::initializeArguments();
77  $this->registerUniversalTagAttributes();
78  $this->registerTagAttribute('target', 'string', 'Target of link', false);
79  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document', false);
80  $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
81  $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
82  $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
83  $this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.');
84  $this->registerArgument('section', 'string', 'The anchor to be added to the URI');
85  $this->registerArgument('linkAccessRestrictedPages', 'bool', 'If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.');
86  $this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
87  $this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
88  $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
89  $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
90  $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
91  }
92 
96  public function ‪render()
97  {
98  $pageUid = isset($this->arguments['pageUid']) ? (int)$this->arguments['pageUid'] : null;
99  $pageType = isset($this->arguments['pageType']) ? (int)$this->arguments['pageType'] : 0;
100  $noCache = isset($this->arguments['noCache']) ? (bool)$this->arguments['noCache'] : false;
101  $noCacheHash = isset($this->arguments['noCacheHash']) ? (bool)$this->arguments['noCacheHash'] : false;
102  $section = isset($this->arguments['section']) ? (string)$this->arguments['section'] : '';
103  $linkAccessRestrictedPages = isset($this->arguments['linkAccessRestrictedPages']) ? (bool)$this->arguments['linkAccessRestrictedPages'] : false;
104  $additionalParams = isset($this->arguments['additionalParams']) ? (array)$this->arguments['additionalParams'] : [];
105  $absolute = isset($this->arguments['absolute']) ? (bool)$this->arguments['absolute'] : false;
106  $addQueryString = isset($this->arguments['addQueryString']) ? (bool)$this->arguments['addQueryString'] : false;
107  $argumentsToBeExcludedFromQueryString = isset($this->arguments['argumentsToBeExcludedFromQueryString']) ? (array)$this->arguments['argumentsToBeExcludedFromQueryString'] : [];
108  $addQueryStringMethod = $this->arguments['addQueryStringMethod'] ?? null;
109  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
110  $uri = $uriBuilder->reset()
111  ->setTargetPageUid($pageUid)
112  ->setTargetPageType($pageType)
113  ->setNoCache($noCache)
114  ->setUseCacheHash(!$noCacheHash)
115  ->setSection($section)
116  ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
117  ->setArguments($additionalParams)
118  ->setCreateAbsoluteUri($absolute)
119  ->setAddQueryString($addQueryString)
120  ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
121  ->setAddQueryStringMethod($addQueryStringMethod)
122  ->build();
123  if ((string)$uri !== '') {
124  $this->tag->addAttribute('href', $uri);
125  $this->tag->setContent($this->renderChildren());
126  $this->tag->forceClosingTag(true);
127  $result = $this->tag->render();
128  } else {
129  $result = $this->renderChildren();
130  }
131  return $result;
132  }
133 }