[TASK] Make Uri/PageViewHelper compilable
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Uri / PageViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
3
4 /* *
5 * This script is part of the TYPO3 project - inspiring people to share! *
6 * *
7 * TYPO3 is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU General Public License version 2 as published by *
9 * the Free Software Foundation. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14 * Public License for more details. *
15 * */
16 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
17
18 /**
19 * A view helper for creating URIs to TYPO3 pages.
20 *
21 * = Examples =
22 *
23 * <code title="URI to the current page">
24 * <f:uri.page>page link</f:uri.page>
25 * </code>
26 * <output>
27 * index.php?id=123
28 * (depending on the current page and your TS configuration)
29 * </output>
30 *
31 * <code title="query parameters">
32 * <f:uri.page pageUid="1" additionalParams="{foo: 'bar'}" />
33 * </code>
34 * <output>
35 * index.php?id=1&foo=bar
36 * (depending on your TS configuration)
37 * </output>
38 *
39 * <code title="query parameters for extensions">
40 * <f:uri.page pageUid="1" additionalParams="{extension_key: {foo: 'bar'}}" />
41 * </code>
42 * <output>
43 * index.php?id=1&extension_key[foo]=bar
44 * (depending on your TS configuration)
45 * </output>
46 */
47 class PageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
48
49 /**
50 * @param int|NULL $pageUid target PID
51 * @param array $additionalParams query parameters to be attached to the resulting URI
52 * @param int $pageType type of the target page. See typolink.parameter
53 * @param bool $noCache set this to disable caching for the target page. You should not need this.
54 * @param bool $noCacheHash set this to suppress the cHash query parameter created by TypoLink. You should not need this.
55 * @param string $section the anchor to be added to the URI
56 * @param bool $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
57 * @param bool $absolute If set, the URI of the rendered link is absolute
58 * @param bool $addQueryString If set, the current query parameters will be kept in the URI
59 * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
60 * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
61 * @return string Rendered page URI
62 */
63 public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $addQueryStringMethod = NULL) {
64 return self::renderStatic(
65 array(
66 'pageUid' => $pageUid,
67 'additionalParams' => $additionalParams,
68 'pageType' => $pageType,
69 'noCache' => $noCache,
70 'noCacheHash' => $noCacheHash,
71 'section' => $section,
72 'linkAccessRestrictedPages' => $linkAccessRestrictedPages,
73 'absolute' => $absolute,
74 'addQueryString' => $addQueryString,
75 'argumentsToBeExcludedFromQueryString' => $argumentsToBeExcludedFromQueryString,
76 'addQueryStringMethod' => $addQueryStringMethod
77 ),
78 $this->buildRenderChildrenClosure(),
79 $this->renderingContext
80 );
81 }
82
83 /**
84 * @param array $arguments
85 * @param callable $renderChildrenClosure
86 * @param RenderingContextInterface $renderingContext
87 * @return string
88 */
89 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
90 $pageUid = $arguments['pageUid'];
91 $additionalParams = $arguments['additionalParams'];
92 $pageType = $arguments['pageType'];
93 $noCache = $arguments['noCache'];
94 $noCacheHash = $arguments['noCacheHash'];
95 $section = $arguments['section'];
96 $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
97 $absolute = $arguments['absolute'];
98 $addQueryString = $arguments['addQueryString'];
99 $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
100 $addQueryStringMethod = $arguments['addQueryStringMethod'];
101
102 $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
103 $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->build();
104 return $uri;
105 }
106
107 }