[TASK] Deprecate render method arguments on ViewHelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Link / ActionViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
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 /**
18 * A view helper for creating links to extbase actions.
19 *
20 * = Examples =
21 *
22 * <code title="link to the show-action of the current controller">
23 * <f:link.action action="show">action link</f:link.action>
24 * </code>
25 * <output>
26 * <a href="index.php?id=123&tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz">action link</f:link.action>
27 * (depending on the current page and your TS configuration)
28 * </output>
29 */
30 class ActionViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper
31 {
32 /**
33 * @var string
34 */
35 protected $tagName = 'a';
36
37 /**
38 * Arguments initialization
39 */
40 public function initializeArguments()
41 {
42 parent::initializeArguments();
43 $this->registerUniversalTagAttributes();
44 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
45 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
46 $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
47 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
48 $this->registerArgument('action', 'string', 'Target action');
49 $this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
50 $this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
51 $this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
52 $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
53 $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
54 $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
55 $this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.');
56 $this->registerArgument('section', 'string', 'The anchor to be added to the URI');
57 $this->registerArgument('format', 'string', 'The requested format, e.g. ".html');
58 $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.');
59 $this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
60 $this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
61 $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
62 $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
63 $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
64 $this->registerArgument('arguments', 'array', 'Arguments for the controller action, associative array');
65 }
66
67 /**
68 * @return string Rendered link
69 */
70 public function render()
71 {
72 $action = $this->arguments['action'];
73 $controller = $this->arguments['controller'];
74 $extensionName = $this->arguments['extensionName'];
75 $pluginName = $this->arguments['pluginName'];
76 $pageUid = (int)$this->arguments['pageUid'];
77 $pageType = (int)$this->arguments['pageType'];
78 $noCache = (bool)$this->arguments['noCache'];
79 $noCacheHash = (bool)$this->arguments['useCacheHash'];
80 $section = (string)$this->arguments['section'];
81 $format = (string)$this->arguments['format'];
82 $linkAccessRestrictedPages = (bool)$this->arguments['linkAccessRestrictedPages'];
83 $additionalParams = (array)$this->arguments['additionalParams'];
84 $absolute = (bool)$this->arguments['absolute'];
85 $addQueryString = (bool)$this->arguments['addQueryString'];
86 $argumentsToBeExcludedFromQueryString = (array)$this->arguments['argumentsToBeExcludedFromQueryString'];
87 $addQueryStringMethod = $this->arguments['addQueryStringMethod'];
88 $parameters = $this->arguments['arguments'];
89 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
90 $uri = $uriBuilder
91 ->reset()
92 ->setTargetPageUid($pageUid)
93 ->setTargetPageType($pageType)
94 ->setNoCache($noCache)
95 ->setUseCacheHash(!$noCacheHash)
96 ->setSection($section)
97 ->setFormat($format)
98 ->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
99 ->setArguments($additionalParams)
100 ->setCreateAbsoluteUri($absolute)
101 ->setAddQueryString($addQueryString)
102 ->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
103 ->setAddQueryStringMethod($addQueryStringMethod)
104 ->uriFor($action, $parameters, $controller, $extensionName, $pluginName);
105 $this->tag->addAttribute('href', $uri);
106 $this->tag->setContent($this->renderChildren());
107 $this->tag->forceClosingTag(true);
108 return $this->tag->render();
109 }
110 }