‪TYPO3CMS  10.4
PageViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
21 
67 class ‪PageViewHelper extends AbstractTagBasedViewHelper
68 {
72  protected ‪$tagName = 'a';
73 
77  public function ‪initializeArguments()
78  {
79  parent::initializeArguments();
80  $this->registerUniversalTagAttributes();
81  $this->registerTagAttribute('target', 'string', 'Target of link', false);
82  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document', false);
83  $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
84  $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
85  $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
86  $this->registerArgument('language', 'string', 'link to a specific language - defaults to the current language, use a language ID or "current" to enforce a specific language', false, null);
87  // @deprecated
88  $this->registerArgument('noCacheHash', 'bool', 'Deprecated: Set this to suppress the cHash query parameter created by TypoLink. You should not need this.', false);
89  $this->registerArgument('section', 'string', 'The anchor to be added to the URI');
90  $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.');
91  $this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
92  $this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
93  $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
94  $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
95  $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
96  }
97 
101  public function ‪render()
102  {
103  if (isset($this->arguments['noCacheHash'])) {
104  trigger_error('Using the argument "noCacheHash" in <f:link.page> ViewHelper has no effect anymore. Remove the argument in your fluid template, as it will result in a fatal error.', E_USER_DEPRECATED);
105  }
106  $pageUid = isset($this->arguments['pageUid']) ? (int)$this->arguments['pageUid'] : null;
107  $pageType = isset($this->arguments['pageType']) ? (int)$this->arguments['pageType'] : 0;
108  $noCache = isset($this->arguments['noCache']) ? (bool)$this->arguments['noCache'] : false;
109  $section = isset($this->arguments['section']) ? (string)$this->arguments['section'] : '';
110  $language = $this->arguments['language'] ?? null;
111  $linkAccessRestrictedPages = isset($this->arguments['linkAccessRestrictedPages']) ? (bool)$this->arguments['linkAccessRestrictedPages'] : false;
112  $additionalParams = isset($this->arguments['additionalParams']) ? (array)$this->arguments['additionalParams'] : [];
113  $absolute = isset($this->arguments['absolute']) ? (bool)$this->arguments['absolute'] : false;
114  $addQueryString = isset($this->arguments['addQueryString']) ? (bool)$this->arguments['addQueryString'] : false;
115  $argumentsToBeExcludedFromQueryString = isset($this->arguments['argumentsToBeExcludedFromQueryString']) ? (array)$this->arguments['argumentsToBeExcludedFromQueryString'] : [];
116  $addQueryStringMethod = $this->arguments['addQueryStringMethod'] ?? null;
118  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
119  $uriBuilder->reset()
120  ->setTargetPageType($pageType)
121  ->setNoCache($noCache)
122  ->setSection($section)
123  ->setLanguage($language)
124  ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
125  ->setArguments($additionalParams)
126  ->setCreateAbsoluteUri($absolute)
127  ->setAddQueryString($addQueryString)
128  ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
129  ;
130 
132  $uriBuilder->setTargetPageUid((int)$pageUid);
133  }
134 
135  if (is_string($addQueryStringMethod)) {
136  $uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
137  }
138 
139  $uri = $uriBuilder->build();
140  if ($uri !== '') {
141  $this->tag->addAttribute('href', $uri);
142  $this->tag->setContent($this->renderChildren());
143  $this->tag->forceClosingTag(true);
144  $result = $this->tag->render();
145  } else {
146  $result = $this->renderChildren();
147  }
148  return $result;
149  }
150 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22