9b8b9f7b3456649c9477744df957fbc40bbd443d
[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 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
18
19 /**
20 * A view helper for creating URIs to TYPO3 pages.
21 *
22 * = Examples =
23 *
24 * <code title="URI to the current page">
25 * <f:uri.page>page link</f:uri.page>
26 * </code>
27 * <output>
28 * index.php?id=123
29 * (depending on the current page and your TS configuration)
30 * </output>
31 *
32 * <code title="query parameters">
33 * <f:uri.page pageUid="1" additionalParams="{foo: 'bar'}" />
34 * </code>
35 * <output>
36 * index.php?id=1&foo=bar
37 * (depending on your TS configuration)
38 * </output>
39 *
40 * <code title="query parameters for extensions">
41 * <f:uri.page pageUid="1" additionalParams="{extension_key: {foo: 'bar'}}" />
42 * </code>
43 * <output>
44 * index.php?id=1&extension_key[foo]=bar
45 * (depending on your TS configuration)
46 * </output>
47 */
48 class PageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper implements CompilableInterface {
49
50 /**
51 * @param int|NULL $pageUid target PID
52 * @param array $additionalParams query parameters to be attached to the resulting URI
53 * @param int $pageType type of the target page. See typolink.parameter
54 * @param bool $noCache set this to disable caching for the target page. You should not need this.
55 * @param bool $noCacheHash set this to suppress the cHash query parameter created by TypoLink. You should not need this.
56 * @param string $section the anchor to be added to the URI
57 * @param bool $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
58 * @param bool $absolute If set, the URI of the rendered link is absolute
59 * @param bool $addQueryString If set, the current query parameters will be kept in the URI
60 * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
61 * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
62 * @return string Rendered page URI
63 */
64 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) {
65 return self::renderStatic(
66 array(
67 'pageUid' => $pageUid,
68 'additionalParams' => $additionalParams,
69 'pageType' => $pageType,
70 'noCache' => $noCache,
71 'noCacheHash' => $noCacheHash,
72 'section' => $section,
73 'linkAccessRestrictedPages' => $linkAccessRestrictedPages,
74 'absolute' => $absolute,
75 'addQueryString' => $addQueryString,
76 'argumentsToBeExcludedFromQueryString' => $argumentsToBeExcludedFromQueryString,
77 'addQueryStringMethod' => $addQueryStringMethod
78 ),
79 $this->buildRenderChildrenClosure(),
80 $this->renderingContext
81 );
82 }
83
84 /**
85 * @param array $arguments
86 * @param callable $renderChildrenClosure
87 * @param RenderingContextInterface $renderingContext
88 * @return string
89 */
90 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
91 $pageUid = $arguments['pageUid'];
92 $additionalParams = $arguments['additionalParams'];
93 $pageType = $arguments['pageType'];
94 $noCache = $arguments['noCache'];
95 $noCacheHash = $arguments['noCacheHash'];
96 $section = $arguments['section'];
97 $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
98 $absolute = $arguments['absolute'];
99 $addQueryString = $arguments['addQueryString'];
100 $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
101 $addQueryStringMethod = $arguments['addQueryStringMethod'];
102
103 $uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
104 $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();
105 return $uri;
106 }
107
108 }