‪TYPO3CMS  9.5
UriViewHelper.php
Go to the documentation of this file.
1 <?php
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 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
20 
35 class ‪UriViewHelper extends AbstractViewHelper
36 {
37  use CompileWithRenderStatic;
38 
42  public function ‪initializeArguments()
43  {
44  $this->registerArgument('useCacheHash', 'bool', 'True whether the cache hash should be appended to the URL', false, false);
45  $this->registerArgument('addQueryStringMethod', 'string', 'Method to be used for query string');
46  $this->registerArgument('action', 'string', 'Target action');
47  $this->registerArgument('arguments', 'array', 'Arguments', false, []);
48  $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
49  $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
50  $this->registerArgument('ajax', 'bool', 'TRUE if the URI should be to an AJAX widget, FALSE otherwise.', false, false);
51  }
52 
59  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
60  {
61  $ajax = $arguments['ajax'];
62 
63  if ($ajax === true) {
64  return static::getAjaxUri($renderingContext, $arguments);
65  }
66  return static::getWidgetUri($renderingContext, $arguments);
67  }
68 
76  protected static function ‪getAjaxUri(RenderingContextInterface $renderingContext, array $arguments)
77  {
78  $controllerContext = $renderingContext->getControllerContext();
79  $action = $arguments['action'];
80  $arguments = $arguments['arguments'];
81  if ($action === null) {
82  $action = $controllerContext->getRequest()->getControllerActionName();
83  }
84  $arguments['id'] = ‪$GLOBALS['TSFE']->id;
85  // @todo page type should be configurable
86  $arguments['type'] = 7076;
87  $arguments['fluid-widget-id'] = $controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier();
88  $arguments['action'] = $action;
89  return '?' . http_build_query($arguments, null, '&');
90  }
91 
99  protected static function ‪getWidgetUri(RenderingContextInterface $renderingContext, array $arguments)
100  {
101  $controllerContext = $renderingContext->getControllerContext();
102  $uriBuilder = $controllerContext->getUriBuilder();
103  $argumentPrefix = $controllerContext->getRequest()->getArgumentPrefix();
104  $parameters = $arguments['arguments'] ?? [];
105  if ($arguments['action'] ?? false) {
106  $parameters['action'] = $arguments['action'];
107  }
108  if (($arguments['format'] ?? '') !== '') {
109  $parameters['format'] = $arguments['format'];
110  }
111  return $uriBuilder->reset()
112  ->setArguments([$argumentPrefix => $parameters])
113  ->setSection($arguments['section'])
114  ->setUseCacheHash($arguments['useCacheHash'])
115  ->setAddQueryString(true)
116  ->setAddQueryStringMethod($arguments['addQueryStringMethod'])
117  ->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
118  ->setFormat($arguments['format'])
119  ->build();
120  }
121 }
‪TYPO3\CMS\Fluid\ViewHelpers\Widget
Definition: AutocompleteViewHelper.php:2
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: UriViewHelper.php:58
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\getAjaxUri
‪static string getAjaxUri(RenderingContextInterface $renderingContext, array $arguments)
Definition: UriViewHelper.php:75
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper\initializeArguments
‪initializeArguments()
Definition: UriViewHelper.php:41
‪$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:98
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper
Definition: UriViewHelper.php:36