[CLEANUP] Replace strlen() with === for zero length check
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Link / PageViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
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 /**
17 * A view helper for creating links to TYPO3 pages.
18 *
19 * = Examples =
20 *
21 * <code title="link to the current page">
22 * <f:link.page>page link</f:link.page>
23 * </code>
24 * <output>
25 * <a href="index.php?id=123">page link</f:link.action>
26 * (depending on the current page and your TS configuration)
27 * </output>
28 *
29 * <code title="query parameters">
30 * <f:link.page pageUid="1" additionalParams="{foo: 'bar'}">page link</f:link.page>
31 * </code>
32 * <output>
33 * <a href="index.php?id=1&foo=bar">page link</f:link.action>
34 * (depending on your TS configuration)
35 * </output>
36 *
37 * <code title="query parameters for extensions">
38 * <f:link.page pageUid="1" additionalParams="{extension_key: {foo: 'bar'}}">page link</f:link.page>
39 * </code>
40 * <output>
41 * <a href="index.php?id=1&extension_key[foo]=bar">page link</f:link.action>
42 * (depending on your TS configuration)
43 * </output>
44 */
45 class PageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
46
47 /**
48 * @var string
49 */
50 protected $tagName = 'a';
51
52 /**
53 * Arguments initialization
54 *
55 * @return void
56 */
57 public function initializeArguments() {
58 $this->registerUniversalTagAttributes();
59 $this->registerTagAttribute('target', 'string', 'Target of link', FALSE);
60 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document', FALSE);
61 }
62
63 /**
64 * @param int|NULL $pageUid target page. See TypoLink destination
65 * @param array $additionalParams query parameters to be attached to the resulting URI
66 * @param int $pageType type of the target page. See typolink.parameter
67 * @param bool $noCache set this to disable caching for the target page. You should not need this.
68 * @param bool $noCacheHash set this to suppress the cHash query parameter created by TypoLink. You should not need this.
69 * @param string $section the anchor to be added to the URI
70 * @param bool $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
71 * @param bool $absolute If set, the URI of the rendered link is absolute
72 * @param bool $addQueryString If set, the current query parameters will be kept in the URI
73 * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
74 * @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
75 * @return string Rendered page URI
76 */
77 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) {
78 $uriBuilder = $this->controllerContext->getUriBuilder();
79 $uri = $uriBuilder->reset()
80 ->setTargetPageUid($pageUid)
81 ->setTargetPageType($pageType)
82 ->setNoCache($noCache)
83 ->setUseCacheHash(!$noCacheHash)
84 ->setSection($section)
85 ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
86 ->setArguments($additionalParams)
87 ->setCreateAbsoluteUri($absolute)
88 ->setAddQueryString($addQueryString)
89 ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
90 ->setAddQueryStringMethod($addQueryStringMethod)
91 ->build();
92 if ((string)$uri !== '') {
93 $this->tag->addAttribute('href', $uri);
94 $this->tag->setContent($this->renderChildren());
95 $result = $this->tag->render();
96 } else {
97 $result = $this->renderChildren();
98 }
99 return $result;
100 }
101
102 }