‪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\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
63 class ‪PageViewHelper extends AbstractViewHelper
64 {
65  use CompileWithRenderStatic;
66 
70  public function ‪initializeArguments()
71  {
72  $this->registerArgument('pageUid', 'int', 'target PID');
73  $this->registerArgument('additionalParams', 'array', 'query parameters to be attached to the resulting URI', false, []);
74  $this->registerArgument('pageType', 'int', 'type of the target page. See typolink.parameter', false, 0);
75  $this->registerArgument('noCache', 'bool', 'set this to disable caching for the target page. You should not need this.', false, false);
76  $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);
77  // @deprecated
78  $this->registerArgument('noCacheHash', 'bool', 'Deprecated: Set this to suppress the cHash query parameter created by TypoLink. You should not need this.', false, null);
79  $this->registerArgument('section', 'string', 'the anchor to be added to the URI', false, '');
80  $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.', false, false);
81  $this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute', false, false);
82  $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false);
83  $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
84  $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
85  }
86 
93  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
94  {
95  $pageUid = $arguments['pageUid'];
96  $additionalParams = $arguments['additionalParams'];
97  $pageType = $arguments['pageType'];
98  $noCache = $arguments['noCache'];
99  if (isset($arguments['noCacheHash'])) {
100  trigger_error('Using the argument "noCacheHash" in <f:uri.page> ViewHelper has no effect anymore. Remove the argument in your fluid template, as it will result in a fatal error.', E_USER_DEPRECATED);
101  }
102  $section = $arguments['section'];
103  $language = $arguments['language'] ?? null;
104  $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
105  $absolute = $arguments['absolute'];
106  $addQueryString = $arguments['addQueryString'];
107  $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
108  $addQueryStringMethod = $arguments['addQueryStringMethod'];
109 
111  $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
112  $uri = $uriBuilder
113  ->reset()
114  ->setTargetPageType($pageType)
115  ->setNoCache($noCache)
116  ->setSection($section)
117  ->setLanguage($language)
118  ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
119  ->setArguments($additionalParams)
120  ->setCreateAbsoluteUri($absolute)
121  ->setAddQueryString($addQueryString)
122  ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
123  ;
124 
126  $uriBuilder->setTargetPageUid((int)$pageUid);
127  }
128 
129  if (is_string($addQueryStringMethod)) {
130  $uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
131  }
132 
133  return $uri->build();
134  }
135 }
‪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\Fluid\ViewHelpers\Uri\PageViewHelper
Definition: PageViewHelper.php:64
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\PageViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: PageViewHelper.php:92
‪TYPO3\CMS\Fluid\ViewHelpers\Uri
Definition: ActionViewHelper.php:16
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\PageViewHelper\initializeArguments
‪initializeArguments()
Definition: PageViewHelper.php:69