[TASK] Streamline phpdoc annotations in EXT:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Uri / ActionViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20
21 /**
22 * A view helper for creating URIs to extbase actions.
23 *
24 * = Examples =
25 *
26 * <code title="URI to the show-action of the current controller">
27 * <f:uri.action action="show" />
28 * </code>
29 * <output>
30 * index.php?id=123&tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz
31 * (depending on the current page and your TS configuration)
32 * </output>
33 */
34 class ActionViewHelper extends AbstractViewHelper
35 {
36 use CompileWithRenderStatic;
37
38 /**
39 * Initialize arguments
40 */
41 public function initializeArguments()
42 {
43 $this->registerArgument('action', 'string', 'Target action');
44 $this->registerArgument('arguments', 'array', 'Arguments', false, []);
45 $this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
46 $this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
47 $this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
48 $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
49 $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter', false, 0);
50 $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.', false, false);
51 $this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.', false, false);
52 $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
53 $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
54 $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);
55 $this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
56 $this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
57 $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false);
58 $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
59 $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
60 }
61
62 /**
63 * @param array $arguments
64 * @param \Closure $renderChildrenClosure
65 * @param RenderingContextInterface $renderingContext
66 * @return string
67 */
68 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
69 {
70 $pageUid = $arguments['pageUid'];
71 $pageType = $arguments['pageType'];
72 $noCache = $arguments['noCache'];
73 $noCacheHash = $arguments['noCacheHash'];
74 $section = $arguments['section'];
75 $format = $arguments['format'];
76 $linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
77 $additionalParams = $arguments['additionalParams'];
78 $absolute = $arguments['absolute'];
79 $addQueryString = $arguments['addQueryString'];
80 $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
81 $addQueryStringMethod = $arguments['addQueryStringMethod'];
82 $action = $arguments['action'];
83 $controller = $arguments['controller'];
84 $extensionName = $arguments['extensionName'];
85 $pluginName = $arguments['pluginName'];
86 $arguments = $arguments['arguments'];
87
88 $uri = $renderingContext->getControllerContext()->getUriBuilder()
89 ->reset()
90 ->setTargetPageUid($pageUid)
91 ->setTargetPageType($pageType)
92 ->setNoCache($noCache)
93 ->setUseCacheHash(!$noCacheHash)
94 ->setSection($section)
95 ->setFormat($format)
96 ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
97 ->setArguments($additionalParams)
98 ->setCreateAbsoluteUri($absolute)
99 ->setAddQueryString($addQueryString)
100 ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
101 ->setAddQueryStringMethod($addQueryStringMethod)
102 ->uriFor($action, $arguments, $controller, $extensionName, $pluginName);
103 return $uri;
104 }
105 }