‪TYPO3CMS  10.4
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 
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
21 
38 class ‪ActionViewHelper extends AbstractTagBasedViewHelper
39 {
43  protected ‪$tagName = 'a';
44 
48  public function ‪initializeArguments()
49  {
50  parent::initializeArguments();
51  $this->registerUniversalTagAttributes();
52  $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
53  $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
54  $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
55  $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
56  $this->registerArgument('action', 'string', 'Target action');
57  $this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
58  $this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
59  $this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
60  $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
61  $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
62  $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
63  // @deprecated
64  $this->registerArgument('noCacheHash', 'bool', 'Deprecated: Set this to suppress the cHash query parameter created by TypoLink. You should not need this.');
65  $this->registerArgument('section', 'string', 'The anchor to be added to the URI');
66  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html');
67  $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.');
68  $this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
69  $this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
70  $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
71  $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
72  $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
73  $this->registerArgument('arguments', 'array', 'Arguments for the controller action, associative array');
74  }
75 
79  public function ‪render()
80  {
81  if (isset($this->arguments['noCacheHash'])) {
82  trigger_error('Using the argument "noCacheHash" in <f:link.action> ViewHelper has no effect anymore. Remove the argument in your fluid template, as it will result in a fatal error.', E_USER_DEPRECATED);
83  }
84  $action = $this->arguments['action'];
85  $controller = $this->arguments['controller'];
86  $extensionName = $this->arguments['extensionName'];
87  $pluginName = $this->arguments['pluginName'];
88  $pageUid = (int)$this->arguments['pageUid'] ?: null;
89  $pageType = (int)$this->arguments['pageType'];
90  $noCache = (bool)$this->arguments['noCache'];
91  $section = (string)$this->arguments['section'];
92  $format = (string)$this->arguments['format'];
93  $linkAccessRestrictedPages = (bool)$this->arguments['linkAccessRestrictedPages'];
94  $additionalParams = (array)$this->arguments['additionalParams'];
95  $absolute = (bool)$this->arguments['absolute'];
96  $addQueryString = (bool)$this->arguments['addQueryString'];
97  $argumentsToBeExcludedFromQueryString = (array)$this->arguments['argumentsToBeExcludedFromQueryString'];
98  $addQueryStringMethod = $this->arguments['addQueryStringMethod'];
99  $parameters = $this->arguments['arguments'];
101  $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
102  $uriBuilder
103  ->reset()
104  ->setTargetPageType($pageType)
105  ->setNoCache($noCache)
106  ->setSection($section)
107  ->setFormat($format)
108  ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
109  ->setArguments($additionalParams)
110  ->setCreateAbsoluteUri($absolute)
111  ->setAddQueryString($addQueryString)
112  ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
113  ;
114 
116  $uriBuilder->setTargetPageUid((int)$pageUid);
117  }
118 
119  if (is_string($addQueryStringMethod)) {
120  $uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
121  }
122 
123  $uri = $uriBuilder->uriFor($action, $parameters, $controller, $extensionName, $pluginName);
124  if ($uri === '') {
125  return $this->renderChildren();
126  }
127  $this->tag->addAttribute('href', $uri);
128  $this->tag->setContent($this->renderChildren());
129  $this->tag->forceClosingTag(true);
130  return $this->tag->render();
131  }
132 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22