-
Notifications
You must be signed in to change notification settings - Fork 638
/
ActionViewHelper.php
112 lines (107 loc) · 5.95 KB
/
ActionViewHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* A view helper for creating links to extbase actions.
*
* = Examples =
*
* <code title="link to the show-action of the current controller">
* <f:link.action action="show">action link</f:link.action>
* </code>
* <output>
* <a href="index.php?id=123&tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz">action link</f:link.action>
* (depending on the current page and your TS configuration)
* </output>
*/
class ActionViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
/**
* Arguments initialization
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
$this->registerArgument('action', 'string', 'Target action');
$this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
$this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
$this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
$this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
$this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
$this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
$this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.');
$this->registerArgument('section', 'string', 'The anchor to be added to the URI');
$this->registerArgument('format', 'string', 'The requested format, e.g. ".html');
$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.');
$this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
$this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
$this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
$this->registerArgument('arguments', 'array', 'Arguments for the controller action, associative array');
}
/**
* @return string Rendered link
*/
public function render()
{
$action = $this->arguments['action'];
$controller = $this->arguments['controller'];
$extensionName = $this->arguments['extensionName'];
$pluginName = $this->arguments['pluginName'];
$pageUid = (int)$this->arguments['pageUid'] ?: null;
$pageType = (int)$this->arguments['pageType'];
$noCache = (bool)$this->arguments['noCache'];
$noCacheHash = (bool)$this->arguments['useCacheHash'];
$section = (string)$this->arguments['section'];
$format = (string)$this->arguments['format'];
$linkAccessRestrictedPages = (bool)$this->arguments['linkAccessRestrictedPages'];
$additionalParams = (array)$this->arguments['additionalParams'];
$absolute = (bool)$this->arguments['absolute'];
$addQueryString = (bool)$this->arguments['addQueryString'];
$argumentsToBeExcludedFromQueryString = (array)$this->arguments['argumentsToBeExcludedFromQueryString'];
$addQueryStringMethod = $this->arguments['addQueryStringMethod'];
$parameters = $this->arguments['arguments'];
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uri = $uriBuilder
->reset()
->setTargetPageUid($pageUid)
->setTargetPageType($pageType)
->setNoCache($noCache)
->setUseCacheHash(!$noCacheHash)
->setSection($section)
->setFormat($format)
->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
->setArguments($additionalParams)
->setCreateAbsoluteUri($absolute)
->setAddQueryString($addQueryString)
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
->setAddQueryStringMethod($addQueryStringMethod)
->uriFor($action, $parameters, $controller, $extensionName, $pluginName);
$this->tag->addAttribute('href', $uri);
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
}