‪TYPO3CMS  11.5
ActionViewHelper.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 
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
22 
37 class ‪ActionViewHelper extends AbstractViewHelper
38 {
39  use CompileWithRenderStatic;
40 
44  public function ‪initializeArguments()
45  {
46  $this->registerArgument('action', 'string', 'Target action');
47  $this->registerArgument('arguments', 'array', 'Arguments', false, []);
48  $this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
49  $this->registerArgument('extensionName', 'string', 'Target Extension Name (without `tx_` prefix and no underscores). If NULL the current extension name is used');
50  $this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
51  $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
52  $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter', false, 0);
53  $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.', false, null);
54  $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);
55  $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
56  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
57  $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);
58  $this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
59  $this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
60  $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false);
61  $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
62  $this->registerArgument('addQueryStringMethod', 'string', 'This argument is not evaluated anymore and will be removed in TYPO3 v12.');
63  }
64 
71  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
72  {
73  if (isset($arguments['addQueryStringMethod'])) {
74  trigger_error('Using the argument "addQueryStringMethod" in <f:uri.action> ViewHelper has no effect anymore and will be removed in TYPO3 v12. Remove the argument in your fluid template, as it will result in a fatal error.', E_USER_DEPRECATED);
75  }
77  $pageUid = (int)($arguments['pageUid'] ?? 0);
79  $pageType = (int)($arguments['pageType'] ?? 0);
81  $noCache = (bool)($arguments['noCache'] ?? false);
83  $language = $arguments['language'] ?? null;
85  $section = $arguments['section'] ?? null;
87  $format = $arguments['format'] ?? null;
89  $linkAccessRestrictedPages = (bool)($arguments['linkAccessRestrictedPages'] ?? false);
91  $additionalParams = $arguments['additionalParams'] ?? null;
93  $absolute = (bool)($arguments['absolute'] ?? false);
95  $addQueryString = $arguments['addQueryString'] ?? false;
97  $argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'] ?? null;
99  $action = $arguments['action'] ?? null;
101  $controller = $arguments['controller'] ?? null;
103  $extensionName = $arguments['extensionName'] ?? null;
105  $pluginName = $arguments['pluginName'] ?? null;
107  $arguments = $arguments['arguments'] ?? [];
108 
110  $uriBuilder = $renderingContext->getUriBuilder();
111  $uriBuilder->reset();
112 
113  if ($pageUid > 0) {
114  $uriBuilder->setTargetPageUid($pageUid);
115  }
116 
117  if ($pageType > 0) {
118  $uriBuilder->setTargetPageType($pageType);
119  }
120 
121  if ($noCache === true) {
122  $uriBuilder->setNoCache($noCache);
123  }
124 
125  if (is_string($section)) {
126  $uriBuilder->setSection($section);
127  }
128 
129  if (is_string($format)) {
130  $uriBuilder->setFormat($format);
131  }
132 
133  if (is_array($additionalParams)) {
134  $uriBuilder->setArguments($additionalParams);
135  }
136 
137  if ($absolute === true) {
138  $uriBuilder->setCreateAbsoluteUri($absolute);
139  }
140 
141  if ($addQueryString === true) {
142  $uriBuilder->setAddQueryString($addQueryString);
143  }
144 
145  if (is_array($argumentsToBeExcludedFromQueryString)) {
146  $uriBuilder->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString);
147  }
148 
149  if ($linkAccessRestrictedPages === true) {
150  $uriBuilder->setLinkAccessRestrictedPages(true);
151  }
152 
153  $uriBuilder->setLanguage($language);
154 
155  return $uriBuilder->uriFor($action, $arguments, $controller, $extensionName, $pluginName);
156  }
157 }
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper\initializeArguments
‪initializeArguments()
Definition: ActionViewHelper.php:43
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: ActionViewHelper.php:70
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:41
‪TYPO3\CMS\Fluid\ViewHelpers\Uri
Definition: ActionViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper
Definition: ActionViewHelper.php:38