‪TYPO3CMS  10.4
UriViewHelper.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\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
22 
37 class ‪UriViewHelper extends AbstractViewHelper
38 {
39  use CompileWithRenderStatic;
40 
44  public function ‪initializeArguments()
45  {
46  // @deprecated
47  $this->registerArgument('useCacheHash', 'bool', 'Deprecated: True whether the cache hash should be appended to the URL', false, null);
48  $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
49  $this->registerArgument('action', 'string', 'Target action');
50  $this->registerArgument('arguments', 'array', 'Arguments', false, []);
51  $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
52  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
53  $this->registerArgument('ajax', 'bool', 'TRUE if the URI should be to an AJAX widget, FALSE otherwise.', false, false);
54  }
55 
62  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
63  {
64  $ajax = $arguments['ajax'];
65 
66  if ($ajax === true) {
67  return static::getAjaxUri($renderingContext, $arguments);
68  }
69  return static::getWidgetUri($renderingContext, $arguments);
70  }
71 
79  protected static function ‪getAjaxUri(RenderingContextInterface $renderingContext, array $arguments)
80  {
81  $controllerContext = $renderingContext->getControllerContext();
82  $action = $arguments['action'];
83  $arguments = $arguments['arguments'];
84  if ($action === null) {
85  $action = $controllerContext->getRequest()->getControllerActionName();
86  }
87  $arguments['id'] = ‪$GLOBALS['TSFE']->id;
88  // @todo page type should be configurable
89  $arguments['type'] = 7076;
90  $arguments['fluid-widget-id'] = $controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
91  $arguments['action'] = $action;
92  return '?' . http_build_query($arguments, '', '&');
93  }
94 
102  protected static function ‪getWidgetUri(RenderingContextInterface $renderingContext, array $arguments)
103  {
104  $controllerContext = $renderingContext->getControllerContext();
106  $uriBuilder = $controllerContext->getUriBuilder();
107  $argumentPrefix = $controllerContext->getRequest()->getArgumentPrefix();
108  $parameters = $arguments['arguments'] ?? [];
109  if ($arguments['action'] ?? false) {
110  $parameters['action'] = $arguments['action'];
111  }
112  if (($arguments['format'] ?? '') !== '') {
113  $parameters['format'] = $arguments['format'];
114  }
115  if (isset($arguments['useCacheHash'])) {
116  trigger_error('Using the argument "useCacheHash" in <f:widget.uri> ViewHelper has no effect anymore. Remove the argument in your fluid template, as it will result in a fatal error.', E_USER_DEPRECATED);
117  }
118  $uriBuilder->reset()
119  ->setArguments([$argumentPrefix => $parameters])
120  ->setSection($arguments['section'])
121  ->setAddQueryString(true)
122  ->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
123  ->setFormat($arguments['format'])
124  ;
125 
126  $addQueryStringMethod = $arguments['addQueryStringMethod'] ?? null;
127  if (is_string($addQueryStringMethod)) {
128  $uriBuilder->setAddQueryStringMethod($addQueryStringMethod);
129  }
130 
131  return $uriBuilder->build();
132  }
133 }
‪TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
Definition: UriBuilder.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\Widget
Definition: AutocompleteViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: UriViewHelper.php:61
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\getAjaxUri
‪static string getAjaxUri(RenderingContextInterface $renderingContext, array $arguments)
Definition: UriViewHelper.php:78
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\initializeArguments
‪initializeArguments()
Definition: UriViewHelper.php:43
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\getWidgetUri
‪static string getWidgetUri(RenderingContextInterface $renderingContext, array $arguments)
Definition: UriViewHelper.php:101
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper
Definition: UriViewHelper.php:38