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