[BUGFIX] Remove addQueryStringMethod parameter from widget links
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Widget / UriViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Widget;
3
4 /*
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23 /**
24 * A view helper for creating URIs to extbase actions within widgets.
25 *
26 * = Examples =
27 *
28 * <code title="URI to the show-action of the current controller">
29 * <f:widget.uri action="show" />
30 * </code>
31 * <output>
32 * index.php?id=123&tx_myextension_plugin[widgetIdentifier][action]=show&tx_myextension_plugin[widgetIdentifier][controller]=Standard&cHash=xyz
33 * (depending on the current page, widget and your TS configuration)
34 * </output>
35 *
36 * @api
37 */
38 class UriViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
39 {
40 /**
41 * Initialize arguments
42 *
43 * @return void
44 * @api
45 */
46 public function initializeArguments()
47 {
48 $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
49 }
50
51 /**
52 * Render the Uri.
53 *
54 * @param string $action Target action
55 * @param array $arguments Arguments
56 * @param string $section The anchor to be added to the URI
57 * @param string $format The requested format, e.g. ".html
58 * @param bool $ajax TRUE if the URI should be to an AJAX widget, FALSE otherwise.
59 * @return string The rendered link
60 * @api
61 */
62 public function render($action = null, $arguments = array(), $section = '', $format = '', $ajax = false)
63 {
64 if ($ajax === true) {
65 return $this->getAjaxUri();
66 } else {
67 return $this->getWidgetUri();
68 }
69 }
70
71 /**
72 * Get the URI for an AJAX Request.
73 *
74 * @return string the AJAX URI
75 */
76 protected function getAjaxUri()
77 {
78 $action = $this->arguments['action'];
79 $arguments = $this->arguments['arguments'];
80 if ($action === null) {
81 $action = $this->controllerContext->getRequest()->getControllerActionName();
82 }
83 $arguments['id'] = $GLOBALS['TSFE']->id;
84 // @todo page type should be configurable
85 $arguments['type'] = 7076;
86 $arguments['fluid-widget-id'] = $this->controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
87 $arguments['action'] = $action;
88 return '?' . http_build_query($arguments, null, '&');
89 }
90
91 /**
92 * Get the URI for a non-AJAX Request.
93 *
94 * @return string the Widget URI
95 */
96 protected function getWidgetUri()
97 {
98 $uriBuilder = $this->controllerContext->getUriBuilder();
99 $argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix();
100 $arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : array();
101 if ($this->hasArgument('action')) {
102 $arguments['action'] = $this->arguments['action'];
103 }
104 if ($this->hasArgument('format') && $this->arguments['format'] !== '') {
105 $arguments['format'] = $this->arguments['format'];
106 }
107 return $uriBuilder->reset()
108 ->setArguments(array($argumentPrefix => $arguments))
109 ->setSection($this->arguments['section'])
110 ->setAddQueryString(true)
111 ->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])
112 ->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))
113 ->setFormat($this->arguments['format'])
114 ->build();
115 }
116 }